hdu-2054

A == B ?

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 120947    Accepted Submission(s): 19337


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
 

题解 :我感觉我写的好麻烦啊,求拯救;

      

注意 :1>  +0.0000  -0    YES

            2>  0000000026   26    YES

            3>  +00026.300000  26.3    YES

            4>  26.0000000   26    YES


#include<stdio.h>
#include<string.h> 
char s1[1000005],s2[1000005],s3[1000005];
void deal_s(char s1[]){
int len1=strlen(s1);
int p1,p2;
if(strstr(s1,".")){                                    // 处理小数后导0。
for(p1=len1-1;s1[p1]=='0';p1--){
len1--;
}
if(s1[p1]=='.'){
s1[p1]='\0';
len1=p1;
}
}

if(strstr(s1,"+")||strstr(s1,"-")){             // 处理 +0和-0
for(p1=len1-1;s1[p1]=='0';p1--);
if(s1[p1]=='+'||s1[p1]=='-'){
strcpy(s1,"0");
}
}

int p3=0;
if(s1[0]=='+'||s1[0]=='-'){                // 处理前导0
for(p1=1;s1[p1]=='0';p1++);
if(p1!=len1){
for(p2=p1;p2<len1;p2++){
s3[p3++]=s1[p2];
}
s3[p3]='\0';
if(s1[0]=='+')                    //  +0000026等于26
 strcpy(s1,s3);
else
 strcpy(s1+1,s3);
}
}
else{
p3=0;
for(p1=0;s1[p1]=='0';p1++);
if(p1!=len1){
for(p2=p1;p2<len1;p2++){
s3[p3++]=s1[p2];
}
s3[p3]='\0';
}
strcpy(s1,s3);
}


int main(){
while(~scanf("%s %s",s1,s2)){
deal_s(s1);
deal_s(s2);
if(!strcmp(s1,s2)){
printf("YES\n");
}
else
printf("NO\n");
}
return 0;
}



猜你喜欢

转载自blog.csdn.net/black_horse2018/article/details/79884673