A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 89356 Accepted Submission(s): 14145
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
Author
8600 && xhd
Source
校庆杯Warm Up
Recommend
linle
#include<stdio.h>#include<string.h>char A[100000];
char B[100000];
void change(char s[])
{
int point=0,len=strlen(s);
for(int i=len-1;i>=0;i--)
if(s[i]=='.') {point=1;break;}
if(point)
{
int K;
for(K=len-1;s[K]=='0';K--) s[K]='\0';
if(s[K]=='.') s[K]='\0';
}
}
int main(void)
{
while(scanf("%s %s",A,B)!=EOF)
{
int lenA=strlen(A),lenB=strlen(B);
//先排除前置0int top_i=0,top_j=0;
while(A[top_i]=='0'&&top_i<lenA-1&&A[top_i+1]!='.') top_i++;//不减到最后一位以防是0while(B[top_j]=='0'&&top_j<lenB-1&&B[top_j+1]!='.') top_j++;
//再排除后置0
change(A);
change(B);
int flag=strcmp(A+top_i,B+top_j);
if(!flag) printf("YES\n");
elseprintf("NO\n");
}
return0;
}
/*这题WA了相当多此来找一个错误,结果是因为复制相同代码段时变量名没改全,还有逆向读取数组元素时用了i++这种低级错误*/