这道题类似Java的大数。
#include <iostream>
#include <string>
using namespace std;
string format(string str){
bool zheng=true;
int ppos=str.find(‘.‘);
int len=str.length();
string s1,s2;
if(ppos!=-1){
int ii;
for(ii=len-1;ii>ppos;ii--){
if(str[ii]!=‘0‘)break;
}
s2=str.substr(ppos,ii-ppos+1);
}
else ppos=len;
int i=0;
if(str[i]==‘-‘){
zheng=false;
i++;
}
for(;i<ppos;i++){
if(str[i]!=‘0‘ ){
s1=str.substr(i,ppos-i);
break;
}
}
if(s1=="")s1="0";
if(s2==".")s2="";
if(!zheng)s1="-"+s1;
if(s1=="-0" && s2=="")s1="0";
//cout<<"s1="<<s1<<" s2="<<s2<<endl;
return s1+s2;
}
int main(){
string a,b;
/*while(cin>>a){
cout<<format(a)<<endl;
}*/
while(cin>>a>>b){
//cout<<a<<" "<<b<<endl;
a=format(a);
b=format(b);
//cout<<" "<<a<<" "<<b<<" ";
if(a==b)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
原文:http://www.cnblogs.com/bruce27/p/4548947.html