您的位置:首页 > 其它

hdu2054 A == B ?(高精度比较)

2014-03-03 18:59 239 查看


A == B ?

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 56411    Accepted Submission(s): 8680


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

 

#include<stdio.h>
#include<string.h>
char a[100004],b[100004];
int dot(char x[])
{
int len=strlen(x),i;
for(i=0; i<len; i++)
{
if(x[i]=='.')
{
int j=len-1;
while(x[j]=='0')
{//去掉末尾的零
len--;
j--;
}
break;
}
}
if(x[len-1]=='.') len--;//去掉整数的小数点
return len;
}
int main()
{
while(scanf("%s%s",a,b)!=EOF)
{
int la=dot(a),lb=dot(b);
if(la!=lb)
{
printf("NO\n");
continue;
}
bool ok=1;
for(int i=0; i<la; i++)
if(a[i]!=b[i])
{
ok=0;
break;
}
if(ok) printf("YES\n");
else printf("NO\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: