hdoj2054

 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");
    } 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值