Hdu2054: A = B?

Source: Internet
Author: User
A = B? Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 60827 accepted submission (s): 9451
Problem descriptiongive you two numbers A and B, if A is equal to B, you shoshould print "yes", or print "no ". inputeach test case contains two numbers A and B. outputfor each case, if A is equal to B, you shoshould print "yes", or print "no ". sample Input
1 22 23 34 3
Sample output
NOYESYESNO

Solution:

1. The question is disgusting. The simpler the question conditions, the more harsh the AC conditions. Pitted once

2. The key lies in the decimal point, removing the leading 0 and the excess trailing 0.

 

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2054

 

 1 #include<stdio.h> 2 #include<string.h> 3 char n[100000], m[100000]; 4 int main() 5 { 6     int i, j, len_n, len_m, flag, len_last, len_late,doc, q, p, count, start; 7     char ch; 8     while(1) 9     {10         memset(n, 0, sizeof(n));11         memset(m, 0, sizeof(m));    12         flag = i = j = doc = count = start = 0;13         while(1)14         {15             if(scanf("%c", &ch) == EOF) return 0;16             if(ch == ‘\n‘ && start == 1) break;17             else if(ch != ‘ ‘ && ch != ‘\n‘ && flag == 0)18             {19                 n[i++] = ch;    20             }21             else if(ch == ‘ ‘ || ch == ‘\n‘)22             {23                 flag = 1;24                 start = 1;25             }26             else m[j++] = ch;27             28         }29         len_n = strlen(n);30         len_m = strlen(m);31         if((n[0] == ‘-‘ && m[0] != ‘-‘) || (n[0] != ‘-‘ && m[0] == ‘-‘)) 32         {33             printf("NO\n");34             continue;35         } 36         for(i = n[0] != ‘-‘? 0:1; i<len_n && n[i] - ‘0‘== 0; i++);37         for(j = m[0] != ‘-‘? 0:1; j<len_m && m[j] - ‘0‘== 0; j++);38         len_n -= i;39         len_m -= j;40         len_last = len_n < len_m? len_n:len_m;41         len_late = len_n + len_m - len_last;42         {43             for(; count < len_last; i++, j++, count++)44             if(n[i] - ‘0‘ != m[j] - ‘0‘) break;45             else if(n[i] == ‘.‘) doc = 1;46             if(count >= len_late)47             {48                 49                 printf("YES\n");50             }51             else52             {53              if(len_n > len_m) 54              {55                  if(doc != 1 && n[i] != ‘.‘) printf("NO\n");56                  else57                  {58                      for(i = n[i] == ‘.‘? i+1: i; i<strlen(n); i++)59                      if(n[i] - ‘0‘ != 0 ) break;60                      if(i>=len_n) printf("YES\n");61                      else printf("NO\n");62                  }63 64              }65              else if(len_n < len_m)66              {67                 if(doc != 1 && m[j] != ‘.‘) printf("NO\n");68                  else69                  {70                      for(j = m[j] == ‘.‘? j+1: j; j<strlen(m); j++)71                      if(m[j] - ‘0‘ != 0 ) break;72                      if(j>=len_m) printf("YES\n");73                      else printf("NO\n");74                  }75              }76              else if(len_n == len_m) printf("NO\n");77             }78         }79         80     }81     return 0;    82 }

 

 

 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.