Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
Inputeach test case contains two numbers A and B.
Outputfor 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
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
void bear(string &str)
{
int len=str.length()-1;
if(strchr(str.c_str(),'.'))
{
while(str[len]=='0')
{
str.erase(len);
len--;
}
if(str[len]=='.')
{
str.erase(len);
}
}
while(str[0]=='0'&&str.length()>1)
{
str.erase(0,1);
}
}
int main()
{
string a,b;
while(cin>>a>>b)
{
bear(a);
bear(b);
if(a.compare(b)==0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
题解:以为这是一道水题。。。。哼!!!!结果这么难。
先用int,WA;又用long long, WA;double,还是WA。。。。。气炸了!
后来才知道,原来数据可以无限的长呀呀呀呀呀呀。。。。
所以数据要定义为字符串型,string.
然后要做点数据调整,去掉多余的0.
strchr函数:
头文件:#include<string.h>
char *strchr(const char* _Str,char _Val)
char *strchr(char* _Str,char _Ch)
功能:查找字符串_Str中首次出现字符_Val的位置
说明:返回首次出现_Val的位置的指针,返回的地址是被查找字符串指针开始的第一个与Val相同字符的指针,如果Str中不存在Val则返回NULL。
返回值:成功则返回要查找字符第一次出现的位置,失败返回NULL
str.length(): string字符串的长度
str.erase(i): 删除第i个字符
string 型字符串a,b比较:a.compare(b)==0,说明相等。