hdu2054 A == B ?
来源:互联网 发布:现在做淘宝还赚钱吗 编辑:程序博客网 时间:2024/05/04 03:43
A == B ?
Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
Input
each test case contains two numbers A and B.
Output
for each case, if A is equal to B, you should print "YES", or print "NO".
Sample Input
1 22 23 34 3
Sample Output
NOYESYESNO
/*分析 : 输入两个数A 、B 判断两个数是否相等。 未给数据范围 所以我们应该考虑用字符串存储来处理它们 因为题目可能会出前导零 后导零的情况 而且最前面可能会有‘+’ ‘-’ 例如 001 与 0001 这两个是相等的 001.00000 与 1 也是相等的 +001.000 与 1 相等 +1 与 -1 不相等 所以我先找出小数点的位置 temp=a.find('.');0~temp 与 temp~a.length(); 分别扫一遍,进行处理字符串。 然后进行比较即可。*/#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <string>#include <cstdlib>using namespace std;string a,b;void work(string a,string b,int len1,int len2){ int temp1=a.find('.'),temp2=b.find('.'); int i,j,k; int front_zero_1=0,back_zero_1=0; if(temp1!=-1)//有逗号 { for(i=0;i<temp1-1;i++) { if(a[i]=='+'||a[i]=='-') continue; if(a[i]!='0') break; if(a[i]=='0') { front_zero_1=1; } } if(front_zero_1==1) { if(a[0]=='+'||a[0]=='-') a.erase(a.begin()+1,a.begin()+i); else a.erase(a.begin(),a.begin()+i); } temp1=a.find('.'); len1=a.length(); for(i=len1-1;i>temp1;i--) { if(a[i]!='0') break; if(a[i]=='0') { back_zero_1=1; continue; } } if(back_zero_1) a.erase(a.end()-len1+i+1,a.end()); } else { for(i=0;i<len1;i++) { if(a[i]=='+'||a[i]=='-') continue; if(a[i]!='0') break; if(a[i]=='0') { front_zero_1=1; continue; } } if(front_zero_1) { if(a[0]=='+'||a[0]=='-') a.erase(a.begin()+1,a.begin()+i); else a.erase(a.begin(),a.begin()+i); } } int front_zero_2=0,back_zero_2=0; if(temp2!=-1)//有逗号 { for(i=0;i<temp2-1;i++) { if(b[i]=='+'||b[i]=='-') continue; if(b[i]!='0') break; if(b[i]=='0') { front_zero_2=1; continue; } } if(front_zero_2) { if(b[0]=='+'||b[0]=='-') b.erase(b.begin()+1,b.begin()+i); else b.erase(b.begin(),b.begin()+i); } temp2=b.find('.'); len2=b.length(); for(i=len2-1;i>temp2;i--) { if(b[i]!='0') break; if(b[i]=='0') { back_zero_2=1; continue; } } if(back_zero_2) b.erase(b.end()-len2+i+1,b.end()); } else { for(i=0;i<len2;i++) { if(b[i]=='+'||b[i]=='-') continue; if(b[i]!='0') break; if(b[i]=='0') { front_zero_2=1; continue; } } if(front_zero_2) { if(b[0]=='+'||b[0]=='-') b.erase(b.begin()+1,b.begin()+i); else b.erase(b.begin(),b.begin()+i); } } if(a.find('.')+1==a.length()) a.erase(a.find('.')); if(b.find('.')+1==b.length()) b.erase(b.find('.')); if(a[0]=='+') a.erase(a.begin()); if(b[0]=='+') b.erase(b.begin()); //cout<<front_zero_1<<" "<<front_zero_2<<endl; //cout<<back_zero_1<<" "<<back_zero_2<<endl; //cout<<a<<endl; //cout<<b<<endl; if(a==b) puts("YES"); else puts("NO");}int main(){ while(cin>>a>>b) work(a,b,a.length(),b.length()); return 0;}
0 0
- hdu2054 A == B ?
- HDU2054:A == B ?
- HDU2054 A == B?
- HDU2054---A == B ?
- HDU2054 A==B?
- HDU2054--A==B?
- hdu2054 A == B ?
- A == B ?(HDU2054)
- HDU2054 A == B ?
- hdu2054 A == B ?
- hdu2054 A == B ?
- HDU2054---A==B?
- HDU2054 A == B ? 模拟题
- 【坑】HDU2054 A==B?
- hdu2054 A == B ?【大数】
- hdu2054 A == B ? (大数)
- HDU2054-A == B ?【字符串处理】
- hdu2054 A == B ?(高精度比较)
- 【BZOJ 1692】[Usaco2007 Dec]队列变换 后缀数组
- 手机电流增大(小计)
- 知道一个Timestamp日期,怎么使用离线查询,查询这一天的数据?
- 论文阅读:Cvpr 2015 Face Alignment by Coarse-to-Fine Shape Searching
- Redis集群Redis-Cluster安装
- hdu2054 A == B ?
- PTA shortest path[1]
- 全局变量和静态变量区别
- tensorflow examples
- 那些天,我刷过的题
- Jackson 枚举序列化/反序列化
- Java之路(一) 一切皆对象
- 兔子-IllegalArgumentException: cannot add an action twice: Generate Butterknife Injections (
- zoj1154