2054 A == B ?

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

 

 1 #include<iostream>
 2 #include <cstring>
 3 #include <stdio.h>
 4 using namespace std;
 5 const int MAX = 100000;
 6 void zero(char *str)//去后前面的零,保留小数点,没小数点的给他加一个
 7 {
 8     int i,len;
 9     len = strlen(str);
10     char *p = strchr(str,'.');
11     if(p == NULL)
12     {
13         str[len] = '.';
14         str[len+1] = '\0';
15     }
16     else
17     {
18         for(i=len-1; i>=0; i--)
19         {
20             if(str[i] != '0')
21             {
22                 str[i+1] = '\0';
23                 return;
24             }
25         }
26     }
27 }
28 int main()
29 {
30     char num1[MAX];
31     char num2[MAX];
32     char *p,*q;
33     while(scanf("%s%s",num1,num2) != EOF)
34     {
35         zero(num1);
36         zero(num2);
37         p=num1;
38         q=num2;
39         while(*p=='0')//去掉前面的零
40         {
41             p++;
42         }
43         while(*q=='0')//去掉前面的零
44         {
45             q++;
46         }
47         if(!strcmp(p,q))
48         {
49             printf("YES\n");
50         }
51         else
52         {
53             printf("NO\n");
54         }
55     }
56     return 0;
57 }
View Code

函数strchr(s,'c')的作用是(查找字符串s中首次出现字符c的位置)

posted @ 2016-03-23 21:01  Wally的博客  阅读(177)  评论(0编辑  收藏  举报