HDU 2054

来源:互联网 发布:中国商业源码网 编辑:程序博客网 时间:2024/06/18 13:52

期末考终于结束了,没有挂科的、继续更新。

A == B ?

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 68679    Accepted Submission(s): 10699


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 22 23 34 3
 


 

Sample Output
NOYESYESNO
 


 

Author
8600 && xhd
 


 

Source
校庆杯Warm Up
 

 

 

就是判断两个数是否相等,一开始以为很简单,但是是高精度的,比如3.0000000000000000000000000000000000000000等于3。计算机是无法精确的表示小数点那么多位的,所以普通的相等不行,必须用字符串做,只要把没用的0去掉就好了。然后用strcmp函数比较。

上代码

 

#include <stdio.h>#include <string.h>int main(){    char s[100000];    char s1[100000];    int i,l,l1,flag,flag1;    while(~scanf("%s%s",s,s1))    {        flag=0;        flag1=0;        l=strlen(s);        l1=strlen(s1);        for(i=0;i<l;i++)        {            if(s[i]=='.')            {                flag=1;                  break;            }        }   //判断第一个数是否为小数点        if(flag)        {            for(l--;l>0;l--)            {                if(s[l]=='0')                    s[l]='\0';  //   从后面开始,将0全部变成结束标志。                else if(s[l]=='.')                {                    s[l]='\0';                    break;  //  遇到小数点也变成结束标志,然后跳出                }                else                    break;   //  遇到数字直接跳出            }        }        for(i=0;i<l1;i++)        {            if(s1[i]=='.')            {                flag1=1;                break;            }        }        if(flag1)        {            for(l1--;l1>0;l1--)            {                if(s1[l1]=='0')                    s1[l1]='\0';                else if(s1[l1]=='.')                {                    s1[l1]='\0';                    break;                }                else                    break;            }         }//  同上。。        if(strcmp(s,s1)==0)            printf("YES\n");//  相等YES ,反之NO。        else            printf("NO\n");    }    return 0;}


 

 

0 0