超级简单的C题目,OJ就是不AC
来源:百度知道 编辑:UC知道 时间:2024/09/22 16:44:51
A == B ?
Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
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
★我的C:
#include <stdio.h>
int main()
{int a,b;
while(scanf("%d %d",&a,&b)!=EOF)
{if(a==b)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
提交后OJ结果是 Output Limit Exceeded
求高手解答并给出能AC的答案
原题地址:来自杭电OJ
http://acm.hdu.edu.cn/showproblem.php?pid=2054
Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
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
★我的C:
#include <stdio.h>
int main()
{int a,b;
while(scanf("%d %d",&a,&b)!=EOF)
{if(a==b)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
提交后OJ结果是 Output Limit Exceeded
求高手解答并给出能AC的答案
原题地址:来自杭电OJ
http://acm.hdu.edu.cn/showproblem.php?pid=2054
题目没要求a,b一定是整数哦,而且可能超出整形或者长整形的表示范围。
看到这,你有解决这道题的想法了吗?
对,没错,就是用字符串保存这两个数,不过如果你以为就简单的strcmp()一下,那你就大错特错了。
还要考虑这种情况,比如
0.10 0.100000000000000
难道它们不相等?
具体OJ系统怎么判断,我不清楚,不过我考虑了这几种情况后AC了。
最后,再说一句,这道题目不简单哦,即使思路有了,你能AC掉,算你有本事!
#include <stdio.h>
#include <string.h>
void A(char *s)
{
int len = strlen(s);
char *p = s + len - 1;
if (strchr(s, '.'))
while (*p == '0') *p-- = 0;
if (*p == '.') *p = 0;
}
int main(void)
{
char *pa, *pb;
char a[100024], b[100024];
while (scanf("%s%s", &a, &b) != EOF)
{
pa = a; pb = b;
while (*pa == '0') pa++;
while (*pb == '0') pb++;
A(pa); A(pb);
puts(strcmp(pa, pb) ? "NO" : "YES");
}
return 0;