1125 - A == B ?——中级
处理后再判断即可,处理过程注意考虑全面。
1 /* 2 Written By. StelaYuri 3 */ 4 #include<iostream> 5 #include<string> 6 using namespace std; 7 string s[2]; 8 void shape(int n){ 9 int i,pj=0,len=s[n].length(),p=0; 10 if(s[n][0]=='-') 11 p=1; 12 for(i=0;i<len;i++) 13 if(s[n][i]=='.'){ 14 pj=1; 15 break; 16 } 17 if(pj){ 18 while(s[n][len-1]=='0') 19 s[n].erase(--len,1); 20 if(s[n][len-1]=='.') 21 s[n].erase(--len,1); 22 } 23 while(s[n][p]=='0'){ 24 if(len>p+1){ 25 s[n].erase(p,1); 26 len--; 27 } 28 else 29 break; 30 } 31 if(s[n][p]=='.') 32 s[n].insert(p,"0"); 33 if(s[n]=="-0") 34 s[n]="0"; 35 } 36 int main(){ 37 ios::sync_with_stdio(0); 38 cin.tie(0);cout.tie(0); 39 while(cin>>s[0]>>s[1]){ 40 shape(0); 41 shape(1); 42 if(s[0]==s[1]) 43 puts("YES"); 44 else 45 puts("NO"); 46 } 47 return 0; 48 }
更多精彩