Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
1 2 2 2 3 3 4 3
NO YES YES NO
题目中要求是判断A和B是否相等,首先易错点
1.A,B不一定在int或long long 的精度范围。
2.A,B的形式可能不同,但是仍然可以相等,比如3.0和3;
3.小数点之后不一定要跟数字。3. 的形式是合法的小数。
代码:
#include <iostream>
using namespace std;
char a[100000], b[100000];
void fun(char *p)
{
int len = strlen(p);
char *p1 = p + len - 1;
if (strchr(p, '.'))
while (*p1 == '0') *p1-- = 0;
if (*p1 == '.') *p1 = 0;
}
int main()
{
while (cin >> a >> b)
{
fun(a), fun(b);
if (strcmp(a, b) == 0)cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}