您的位置:首页 > 其它

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

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


。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: