http://acm.hdu.edu.cn/showproblem.php?pid=2054
用得泛型编程 ,字符串比较 去掉前导0,如果有小数点,去掉小数点后面连续的0,注意一些特殊数据 如“34.00与34”,“000034与34.0000”,“34.00012400与34.000124”等数据,
#include<iostream>
#include<string>
using namespace std;
bool isdot( string a)//判断是否存在小数点
{
string::iterator it;
for( it = a.begin();it < a.end();it++)
{
if( *it=='.')
{
return true;
}
}
return false;
}
int main()
{
string a,b;
string::iterator it1,it2;
while( cin >> a >> b)
{
it1= a.begin();
it2= b.begin();
while( *it1=='0')//去掉前导0
{
it1++;
}
a.erase(a.begin(),it1);
while( *it2=='0')//去掉前导0
{
it2++;
}
b.erase(b.begin(),it2);
if( isdot(a))//如果有小数点,去掉后导0
{
it1=a.end()-1;
if( *it1=='0')
{
while(*it1=='0')
{
it1--;
}
}
if(*it1=='.')it1--;
a.erase(it1+1,a.end());
}
if( isdot(b))//如果有小数点,去掉后导0
{
it2=b.end()-1;
if( *it2=='0')
{
while(*it2=='0')
{
it2--;
}
}
if(*it2=='.')it2--;
b.erase(it2+1,b.end());
}
cout << (a==b?"YES\n":"NO\n");
}
system("pause");
}