HDOJ 2054 A == B ?(大数)
2016-12-20 20:24
197 查看
A == B ?
[b]Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 98202 Accepted Submission(s): 15578
[/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
#include<stdio.h> #include<string.h> char a[100001],b[100001]; int main() { int i,j,flag,flag1,flag2,temp1,temp2,s1,s2,len1,len2,t1,t2; while(~scanf("%s%s",a,b)) { len1=strlen(a); len2=strlen(b); flag1=flag2=s1=s2=0; if(a[0]=='-') { flag1=1; s1++; } else if(a[0]=='+') s1++; if(b[0]=='-') { flag2=1; s2++; } else if(b[0]=='+') s2++; for(;a[s1]=='0';s1++) //去掉前导0 a[s1]='!'; for(;b[s2]=='0';s2++) b[s2]='!'; temp1=temp2=0; for(i=s1;i<len1;i++) //判断有无小数点 if(a[i]=='.') { temp1=1; break; } for(i=s2;i<len2;i++) if(b[i]=='.') { temp2=1; break; } t1=len1-1; t2=len2-1; if(temp1) //去掉后导0 for(;a[t1]=='0';t1--) a[t1]='!'; if(a[t1]=='.') //去掉不必要的小数点 { a[t1]='!'; t1--; } if(temp2) for(;b[t2]=='0';t2--) b[t2]='!'; if(b[t2]=='.') { b[t2]='!'; t2--; } if((t1-s1)!=(t2-s2)) //判断转化后的数字长度是否一致 printf("NO\n"); else if(t1==(s1-1)&&t2==(s2-1)) //正负0的情况 printf("YES\n"); else if(flag1!=flag2) //符号相反 printf("NO\n"); else { flag=1; for(i=s1,j=s2;i<=t1;i++,j++) //逐位比较 if(a[i]!=b[j]) { flag=0; break; } if(flag) printf("YES\n"); else printf("NO\n"); } } return 0; }
几组特殊的测试数据:
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
YES
00000000000000000002222 2222
YES
200 200000
NO
0.00002 0.000020000000000000000000000000000000
YES
00000000000000000000.00002 0.0000200000
YES
0022000 000000000002200
YES
-0022.00200 -000000000000022.002000000000000000000
YES
+0.00 0.000000000000000
YES
000000000 0000000000000
YES
000001.00000 1
YES
-0001.000 0001
NO
-0 0
YES
相关文章推荐
- HDOJ-2054(大数比较)(A == B ?)
- HDOJ 2054 A == B ?(精确大数相等)
- HDOJ2054(大数处理)
- hdoj 2054 A == B ?【大数判断题】
- HDOJ2054 A == B ?(又一道大数题目)
- 2054 大数模拟 水题(略坑)
- hdoj1001简单题、大数
- BestCoder Round #63 (div.2) HDOJ5568 sequence2(dp + 大数)
- HDOJ 题目1002A + B Problem II (大数)
- HDOJ 1715 大斐波数(大数+打表)
- hdoj 5666 Segment (大数取模)(俄罗斯乘法)
- 【大数问题】 HDOJ 1316 How Many Fibs?
- 求 n! (大数问题)----------HDOJ1042
- HDOJ-1042 大数处理时的更优方法
- HDOJ 1018 Big Number(大数位数公式)
- 杭电OJ(HDOJ)1063题:Exponentiation(大数操作——幂运算)
- HDOJ-1297 Children’s Queue[递推+大数]
- HDOJ1002(大数相加)
- HDOJ---1261 字串数[组合+大数]
- hdoj1212(大数取余)Big Number