HDU 2054

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

思路:

此题关键是找小数点,找到小数点把最后面无效的零去掉再比较就OK;

代码如下:


  
  
  1. #include <cstdio>
  2. #include <cstring>
  3. char a[ 100017], b[ 100017];
  4. void re(char s[])
  5. {
  6. int len = strlen(s);
  7. int p = 0;
  8. for( int i = 0; i < len; i++)
  9. {
  10. if(s[i] == '.')
  11. {
  12. p = 1;
  13. break;
  14. }
  15. }
  16. if(p)
  17. {
  18. for( int i = len -1; i >= 0; i--)
  19. {
  20. if(s[i] == '0')
  21. s[i] = '\0';
  22. else
  23. break;
  24. len--;
  25. }
  26. if(s[len -1] == '.')
  27. s[len -1] = '\0';
  28. }
  29. }
  30. int main()
  31. {
  32. while(~ scanf( "%s%s",a,b))
  33. {
  34. re(a);
  35. // printf("%s\n",a);
  36. re(b);
  37. // printf("%s\n",b);
  38. if( strcmp(a,b))
  39. printf( "NO\n");
  40. else
  41. printf( "YES\n");
  42. }
  43. return 0;
  44. }

猜你喜欢

转载自blog.csdn.net/shf1730797676/article/details/89302401