HDU 2054 A==B
2012-03-28 17:09
387 查看
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
Sample Output
很明显这是一道坑爹题……于是我还是被坑了。。
试了几次WA之后,终于AC了,其实很简单,但是需要严谨。
思路:这题由于没有给出条件,因此会出现上千甚至上万位数的测试数据,于是必须用字符串来解题。
然后难点就是去除前置的的0和小数点后不为零数字后面的0,实际上就这两点而已。
用的是C++,代码不长:
。。。
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 2 2 2 3 3 4 3
Sample Output
NO YES YES NO
很明显这是一道坑爹题……于是我还是被坑了。。
试了几次WA之后,终于AC了,其实很简单,但是需要严谨。
思路:这题由于没有给出条件,因此会出现上千甚至上万位数的测试数据,于是必须用字符串来解题。
然后难点就是去除前置的的0和小数点后不为零数字后面的0,实际上就这两点而已。
用的是C++,代码不长:
#include <iostream>//2054 A==B #include <string> using namespace std; void change(string &str) { if( strchr(str.c_str() , '.' ) ) { int last=str.length(); while(str[--last]=='0') str.erase(last,1) ; //删除后置0 if( str[last]=='.' ) str.erase(last,1) ; //若全为0,删除小数点 } while(str[0]=='0')//前置0的处理 { if( str.length()!=1 ) str.erase(0,1);//若全为0,则保存一个0 else return; } } void main() { string a,b; while(cin>>a>>b) { change(a); change(b); if(a.compare(b)==0) cout<<"YES"<<endl; else cout<<"NO"<<endl; } }
。。。
相关文章推荐
- HDU 2054 A == B ?
- hdu 2054 A==B?
- hdu 2054 A==B?
- HDU 2054 A==B? 大数
- HDU 2054 A == B ?
- hdu 2054 A == B ? (java大数)
- hdu 1055 & poj 2054 Color a Tree 树&贪心 找最大费用点和父节点合并
- hdu 2054 A == B ? 坑人的题目
- hdu 2054
- HDU 2054 A == B ?A
- HDU 2054 大数比较
- hdu 2054 A == B ?
- A == B_hdu_2054(很有意思).java
- hdu_2054_A == B_201311301601
- HDU 2054
- HDU 2054 A == B ?
- HDU 2054 又见GCD(水题??)
- hdu 2054 A == B ? 解题报告
- HDU 2054 A==B?
- HDU-2054