HDUOJ-----A == B ?

A == B ?

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

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
 

 

Author
8600 && xhd
 

 

Source
 

 

此题解法:分整数和小数两部分来比较即可!!但要注意的事情还是比较多的

需要考虑:

+0.000    0.00

YES

+0.00 -0.00

YES

+0001.00 1

YES

+000.0000100  .00001

YES

代码如下:

 1 #include<cstdio>

 2 #include<cstring>

 3 #define MAX 20000

 4 char a[MAX],b[MAX];

 5 char ra[MAX],apoint[MAX],

 6      rb[MAX],bpoint[MAX];

 7 void func(char *a,char *ra,char *apoint)

 8 {

 9     int i=0,k=0;

10     bool flag=true;

11     int len=strlen(a);

12     if(*a=='+')i++;

13     else if(a[0]=='-')

14     {

15         ra[k++]='-' ;

16         i=k;

17     }

18     for( ; a[i]=='0'&&i<len ; i++ );

19 

20     for( ;a[i]!='.'&&i<len ; i++ )

21     {  

22         ra[k++] = a[i] ;

23     }

24     int j;

25          a[i]=='.'? i++ : i ;

26    for(j=len-1;a[j]=='0'&&j>=i;j--);

27    

28    for(k=0 ; i<=j ; i++)

29     {

30         apoint[k++]=a[i];

31     }

32 }

33 

34 int main( void )

35 {

36     while(scanf("%s%s",a,b)!=EOF)

37     {

38         memset(ra,'\0',sizeof ra);

39         memset(apoint,'\0',sizeof apoint);

40         memset(rb,'\0',sizeof rb);

41         memset(bpoint,'\0',sizeof bpoint);

42         func(a,ra,apoint);

43         func(b,rb,bpoint);

44       if(strcmp(ra,rb)==0&&strcmp(apoint,bpoint)==0)

45           puts("YES");

46       else if((*rb=='-'&&*(rb+1)=='\0')&&strcmp(apoint,bpoint)==0)

47           puts("YES");

48      else if(*ra=='-'&&*(ra+1)=='\0'&&strcmp(apoint,bpoint)==0)

49                puts("YES");

50      else

51           puts("NO");

52     }

53     return 0;

54 }
View Code

 

 

你可能感兴趣的:(HDU)