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