主要是关于!=string::npos的用法和substr的用法

 1 #include <iostream>
 2 #include <cstring>
 3 #include<stdlib.h>
 4 
 5 using namespace std;
 6 void del(string & str)
 7 {
 8     int i=str.size();
 9     if(str.find('.')!=string::npos)//表示判断是否找到
10     {
11         int j;
12         for(j=i-1;str[j]=='0';j--);
13         str=str.substr(0,j);
14         if(str[j]=='.')str=str.substr(0,j-1);//substr(a,b)函数作用在于返回rank(下标)从a到b的字符串
15 
16     }
17 }
18 
19 int main()
20 {
21     string a,b;
22     while(cin>>a>>b)
23     {
24         int x;
25         del(a);
26         del(b);
27         x=strcmp(a.c_str(),b.c_str());
28         if(x==0)cout<<"YES"<<endl;
29         else cout<<"NO"<<endl;
30 
31     }
32     return 0;
33 }

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄