A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 133531 Accepted Submission(s): 21293
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
这题真是一个巨坑
因为题中没有给出A,B是什么样的数,所以需要考虑的不仅仅是 大数 的问题还要考虑 小数 的问题。
我一开始没注意到小数点后还有数要去比就直接把小数点换成'\0'结果就WA了好几次(2333);
代表测试样例
0.0 0
YES
1.222 1
NO
样例代码
#include <bits/stdc++.h>
using namespace std;
char a[100000],b[100000];
int main()
{
while(~scanf("%s%s",a,b))
{
int oja=0,ojb=0;
int lena=strlen(a);
int lenb=strlen(b);
for(int i=0; i <= lena-1; i++)
if(a[i] == '.')
oja=1;
for(int i=0; i <= lenb-1; i++)
if(b[i] == '.')
ojb=1;
if(oja == 1) //下面的可以单独定义一个函数,不过TL不TL就不知道了
{
while(a[lena-1] == '0')
{
a[lena-1]='\0';
lena--;
}
if(a[lena-1] == '.')
a[lena-1] = '\0';
}
if(ojb == 1)
{
while(b[lenb-1] == '0')
{
b[lenb-1]='\0';
lenb--;
}
if(b[lenb-1] == '.')
b[lenb-1] = '\0';
}
if(strcmp(a,b) == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}