HDUOJ-----A == B ?

时间:2022-05-05
本文章向大家介绍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

校庆杯Warm Up

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

需要考虑:

+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,'',sizeof ra);
39         memset(apoint,'',sizeof apoint);
40         memset(rb,'',sizeof rb);
41         memset(bpoint,'',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)=='')&&strcmp(apoint,bpoint)==0)
47           puts("YES");
48      else if(*ra=='-'&&*(ra+1)==''&&strcmp(apoint,bpoint)==0)
49                puts("YES");
50      else
51           puts("NO");
52     }
53     return 0;
54 }