A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 53634 Accepted Submission(s): 8215
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
1 #include <stdio.h> 2 #include <string.h> 3 #define MAX 100000 4 5 char str1[MAX+10],str2[MAX+10]; 6 int a1[MAX+10],a2[MAX+10],b1[MAX+10],b2[MAX+10]; 7 8 int bijiao(char *str1,char *str2) 9 { 10 int len1,len2; 11 int i,j,k,t; 12 for(i=0;i<MAX+10;i++) 13 a1[i]=a2[i]=b1[i]=b2[i]=0; 14 len1=strlen(str1); 15 for(i=0;i<len1;i++) 16 if(str1[i]=='.') 17 {t=i;break;} 18 if(i>=len1) 19 t=len1; 20 for(j=0,i=t-1;i>=0;i--) 21 a1[j++]=str1[i]-'0'; 22 for(j=0,i=t+1;i<len1;i++) 23 a2[j++]=str1[i]-'0'; 24 len2=strlen(str2); 25 for(i=0;i<len2;i++) 26 if(str2[i]=='.') 27 {t=i;break;} 28 if(i>=len2) 29 t=len2; 30 for(j=0,i=t-1;i>=0;i--) 31 b1[j++]=str2[i]-'0'; 32 for(j=0,i=t+1;i<len2;i++) 33 b2[j++]=str2[i]-'0'; 34 if(len1==0&&len2==0) 35 return 0; 36 for(i=0;i<MAX;i++) 37 { 38 if(a1[i]!=0||a2[i]!=0||b1[i]!=0||b2[i]!=0) 39 break; 40 } 41 if(i>=MAX) 42 return 2; 43 for(i=0;i<MAX;i++) 44 { 45 if(a1[i]!=b1[i]) 46 { 47 k=0; 48 break; 49 } 50 } 51 if(i>=MAX) 52 { 53 for(i=0;i<MAX;i++) 54 { 55 if(a2[i]!=b2[i]) 56 { 57 k=0; 58 break; 59 } 60 } 61 if(i>=MAX) 62 k=1; 63 } 64 return k; 65 //puts(str1); 66 //puts(str2); 67 } 68 int main() 69 { 70 while(scanf("%s%s",str1,str2)!=EOF) 71 { 72 int t=0,k; 73 //gets(str2); 74 //getchar(); 75 if((str1[0]>='0'&&str1[0]<='9')&&(str2[0]>='0'&&str2[0]<='9')) 76 k=bijiao(str1,str2); 77 else if((str1[0]>='0'&&str1[0]<='9')&&(str2[0]=='+')) 78 k=bijiao(str1,str2+1); 79 else if((str2[0]>='0'&&str2[0]<='9')&&(str1[0]=='+')) 80 k=bijiao(str1+1,str2); 81 else if(str1[0]==str2[0]) 82 k=bijiao(str1+1,str2+1); 83 else 84 { 85 t=bijiao(str1+1,str2+1); 86 if(t==2) 87 k=1; 88 else 89 k=0; 90 } 91 if(k) 92 printf("YES "); 93 else 94 printf("NO "); 95 } 96 return 0; 97 }
wa了n次,原来是数组开的太小