A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 98202 Accepted Submission(s): 15578
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<stdio.h>
#include<string.h>
char a[100001],b[100001];
int main()
{
int i,j,flag,flag1,flag2,temp1,temp2,s1,s2,len1,len2,t1,t2;
while(~scanf("%s%s",a,b))
{
len1=strlen(a);
len2=strlen(b);
flag1=flag2=s1=s2=0;
if(a[0]=='-')
{
flag1=1;
s1++;
}
else if(a[0]=='+')
s1++;
if(b[0]=='-')
{
flag2=1;
s2++;
}
else if(b[0]=='+')
s2++;
for(;a[s1]=='0';s1++) //去掉前导0
a[s1]='!';
for(;b[s2]=='0';s2++)
b[s2]='!';
temp1=temp2=0;
for(i=s1;i<len1;i++) //判断有无小数点
if(a[i]=='.')
{
temp1=1;
break;
}
for(i=s2;i<len2;i++)
if(b[i]=='.')
{
temp2=1;
break;
}
t1=len1-1;
t2=len2-1;
if(temp1) //去掉后导0
for(;a[t1]=='0';t1--)
a[t1]='!';
if(a[t1]=='.') //去掉不必要的小数点
{
a[t1]='!';
t1--;
}
if(temp2)
for(;b[t2]=='0';t2--)
b[t2]='!';
if(b[t2]=='.')
{
b[t2]='!';
t2--;
}
if((t1-s1)!=(t2-s2)) //判断转化后的数字长度是否一致
printf("NO\n");
else if(t1==(s1-1)&&t2==(s2-1)) //正负0的情况
printf("YES\n");
else if(flag1!=flag2) //符号相反
printf("NO\n");
else
{
flag=1;
for(i=s1,j=s2;i<=t1;i++,j++) //逐位比较
if(a[i]!=b[j])
{
flag=0;
break;
}
if(flag) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
几组特殊的测试数据:
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
YES
00000000000000000002222 2222
YES
200 200000
NO
0.00002 0.000020000000000000000000000000000000
YES
00000000000000000000.00002 0.0000200000
YES
0022000 000000000002200
YES
-0022.00200 -000000000000022.002000000000000000000
YES
+0.00 0.000000000000000
YES
000000000 0000000000000
YES
000001.00000 1
YES
-0001.000 0001
NO
-0 0
YES