首页 > 代码库 > HDU2054:A == B ?

HDU2054:A == B ?

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 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 22 23 34 3

Sample Output

NOYESYESNO

 解题思路:

    1. 一看题目就觉得恶心,题目条件越简单,AC的条件就越苛刻。被坑了一次

    2.关键在于小数点,去除前导0和多余的后置0。

 

 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=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 }