落絮飞雁的个人网站

顺流而下,把梦做完

HDOJ2054:A==B? 字符串处理、看似水题

Problem Description
Give you two numbers A and B, if A is equal to B, you should print “YES”, or print “NO”.

 

Input
each test case contains two numbers A and B.

 

Output
for each case, if A is equal to B, you should print “YES”, or print “NO”.

 

Sample Input
1 2
2 2
3 3
4 3

 

Sample Output
NO
YES
YES
NO
主要考虑:数字中负号的处理、前导和后导零的问题;尽量开大数组。

 

#include
#include
using namespace std;
char a[100000], b[100000];
bool is(char *p)
{
	for (; *p != ''; p++)
	if (*p == '.')return true;
	return false;
}

void det(char *p)
{
	for (; *p != ''; p++);
	p--;
	for (; *p == '0'; p--)
		*p = '';
	if (*p == '.')*p = '';
}

int main()
{
	while (cin >> a >> b)
	{
		if (is(a))det(a);
		if (is(b))det(b);
		if (strcmp(a, b) == 0)cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	return 0;
}

原文标题:HDOJ2054:A==B? 字符串处理、看似水题|落絮飞雁的个人网站
原文链接:https://www.luoxufeiyan.com/2014/12/11/hdoj2054%ef%bc%9aab-%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%a4%84%e7%90%86%e3%80%81%e7%9c%8b%e4%bc%bc%e6%b0%b4%e9%a2%98/
授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。