ACM HDU 2054 A == B ?
A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 40699 Accepted Submission(s): 6340
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
Recommend
linle
#include<stdio.h> #include<string.h> char n[100000], m[100000]; int main() { int i, j, len_n, len_m, flag, len_last, len_late,doc, q, p, count, start; char ch; while(1) { memset(n, 0, sizeof(n)); memset(m, 0, sizeof(m)); flag = i = j = doc = count = start = 0; while(1) { if(scanf("%c", &ch) == EOF) return 0; if(ch == '\n' && start == 1) break; else if(ch != ' ' && ch != '\n' && flag == 0) { n[i++] = ch; } else if(ch == ' ' || ch == '\n') { flag = 1; start = 1; } else m[j++] = ch; } len_n = strlen(n); len_m = strlen(m); if((n[0] == '-' && m[0] != '-') || (n[0] != '-' && m[0] == '-')) { printf("NO\n"); continue; } for(i = n[0] != '-'? 0:1; i<len_n && n[i] - '0'== 0; i++); for(j = m[0] != '-'? 0:1; j<len_m && m[j] - '0'== 0; j++); len_n -= i; len_m -= j; len_last = len_n < len_m? len_n:len_m; len_late = len_n + len_m - len_last; { for(; count < len_last; i++, j++, count++) if(n[i] - '0' != m[j] - '0') break; else if(n[i] == '.') doc = 1; if(count >= len_late) { printf("YES\n"); } else { if(len_n > len_m) { if(doc != 1 && n[i] != '.') printf("NO\n"); else { for(i = n[i] == '.'? i+1: i; i<strlen(n); i++) if(n[i] - '0' != 0 ) break; if(i>=len_n) printf("YES\n"); else printf("NO\n"); } } else if(len_n < len_m) { if(doc != 1 && m[j] != '.') printf("NO\n"); else { for(j = m[j] == '.'? j+1: j; j<strlen(m); j++) if(m[j] - '0' != 0 ) break; if(j>=len_m) printf("YES\n"); else printf("NO\n"); } } else if(len_n == len_m) printf("NO\n"); } } } return 0; }
解题报告:
1. 一看题目就觉得恶心,题目条件越简单,AC的条件就越苛刻,数组未开足, Runtime Error 了一次。
2. 由于我的无知,未考虑小数点的情况,WA = 1 ,其实是有想到小数点的情况,但侥幸的心理对于我这样的菜菜鸟来说是拉不出来的
3.开始考虑小数点,WA + 1;
4. 开始考虑小数点后面的0,WA+1;
5. 考虑数字前面的0, WA + 1;
6. 输入出现了问题,处理换行符
总的来说,能再坚持一点点就坚持下去,给你 !AC 就是说明你程序出现了问题,当然有时会遇到让你趾高气扬的时候,就是题目和AC的代码有点难以恰和的时候,但更多的情况是自己的代码真的出问题,所以你得谦虚!
![物役记](https://s2.ax1x.com/2019/05/26/VE5YD0.jpg)
更多内容请关注个人微信公众号 物役记 (微信号:materialchains)
作者:雪影蓝枫
本文版权归作者和博客园共有,欢迎转载,未经作者同意须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。