处理后再判断即可,处理过程注意考虑全面。
#include<iostream> #include<string> using namespace std; string s[2]; void shape(int n){ int i,pj=0,len=s[n].length(),p=0; if(s[n][0]=='-') p=1; for(i=0;i<len;i++) if(s[n][i]=='.'){ pj=1; break; } if(pj){ while(s[n][len-1]=='0') s[n].erase(--len,1); if(s[n][len-1]=='.') s[n].erase(--len,1); } while(s[n][p]=='0'){ if(len>p+1){ s[n].erase(p,1); len--; } else break; } if(s[n][p]=='.') s[n].insert(p,"0"); if(s[n]=="-0") s[n]="0"; } int main(){ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); while(cin>>s[0]>>s[1]){ shape(0); shape(1); if(s[0]==s[1]) puts("YES"); else puts("NO"); } return 0; }