当前位置: 代码迷 >> 综合 >> hdu - 2054 - A == B ?
  详细解决方案

hdu - 2054 - A == B ?

热度:73   发布时间:2024-01-10 13:52:59.0

题意:输入两个数字A, B,如果A等于B,输出“YES”,否则输出“NO”。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2054

——>>开始以为,好简单呀,直接输入两个string,然后用==判断,一次WA,改用直接输入两个double,然后用==判断,再次WA……原来,这不是那么好过的题!要考虑前导0与有小数点的尾0。不过貌似不用考虑负数的情况,因为我的程序过不了0, -0还有-12, -012这样的数据,但可以AC! (最后一次WA,是因为开了10000+10的大小,还差一个0,这题目……)

#include <cstdio>
#include <cstring>using namespace std;const int maxn = 100000 + 10;char A[maxn], B[maxn];void simplify(char *s)
{while(*s == '0') s++;if(strchr(s, '.')){int len = strlen(s);char *p = s + len - 1;while(*p == '0') *(p--) = 0;if(*p == '.') *p = 0;}
}
int main()
{while(~scanf("%s%s", A, B)){simplify(A);simplify(B);if(strcmp(A, B) == 0) printf("YES\n");else printf("NO\n");}return 0;
}