A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 125026 Accepted Submission(s): 20080
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
题意:
判断两个数是否相等。
思路:
用字符串存,把小数点后多余的0给去掉再比较。
刚看到这题一开始想了很多,后来又想可能是大水题吧,写了之后发现输出超限,就感觉没那么简单,去看了别人写的才发现高精度的数和小数点后有多余0的情况都要考虑在内,要不1.0000000跟1.00都过不去。但是我不知道为什么对前导0不做要求。
代码:
#include<stdio.h>
#include<string.h>
char a[100000],b[100000];
void change(char s[])
{
int i,len;
len=strlen(s);
if(strstr(s,"."))
{
for(i=len-1;s[i]=='0';i--)
{
s[i]='\0';
len--;
}
}
if(s[len-1]=='.')
s[len-1]='\0';
}
int main()
{
while(scanf("%s%s",a,b)!=EOF)
{
change(a);
change(b);
if(strcmp(a,b))
printf("NO\n");
else
printf("YES\n");
}
return 0;
}