Comparing Two Long Integers
来源:互联网 发布:淘宝商店如何开通花呗 编辑:程序博客网 时间:2024/06/07 11:29
Description
You are given two very long integers a, b (leading zeroes are allowed). You should check what numbera or b is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to usescanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead ofScanner/System.out in Java. Don't use the function input() inPython2 instead of it use the function raw_input().
Input
The first line contains a non-negative integer a.
The second line contains a non-negative integer b.
The numbers a, b may contain leading zeroes. Each of them contains no more than106 digits.
Output
Print the symbol "<" if a < b and the symbol ">" ifa > b. If the numbers are equal print the symbol "=".
Sample Input
910
<
1110
>
0001234512345
=
01239
>
0123111
>
#include <iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>using namespace std;int main(){ char a[1000005], b[1000005]; int n, m, i, j, x = 0, y = 0; scanf("%s%s", a, b); n = strlen(a); m=strlen(b); for (i = 0; i < n; i++) { if (a[i] == '0') x++; else break; } for (i = 0; i < m; i++) { if (b[i] == '0') y++; else break; } if (n - x > m - y) printf(">\n"); else if (n - x < m - y) printf("<\n"); else { for (i = x; i < n; i++) { if (a[i] > b[y]) { printf(">\n"); break; } else if (a[i] < b[y]) { printf("<\n"); break; } else if (a[i] == b[y]) { y++; continue; } } if (i == n) printf("=\n"); } return 0;}
- Comparing Two Long Integers
- A. Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- CF Comparing Two Long Integers 616A
- cf 616A Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- Educational Codeforces Round 5 A. Comparing Two Long Integers
- CodeForce 616A Comparing Two Long Integers 字符串比较
- CodeForces 616 A. Comparing Two Long Integers(水~)
- CodeForces 616A Comparing Two Long Integers【字符串】
- day4 CodeForces 616A Comparing Two Long Integers
- Educational Codeforces Round 5-A. Comparing Two Long Integers(模拟)
- Educational Codeforces Round 5 A. Comparing Two Long Integers (水)
- Codeforces--616A--Comparing Two Long Integers(模拟水题)
- CodeForces - 616A Comparing Two Long Integers (模拟)比较两个数大小
- Comparing Two Bitmaps for Equality
- Chewbaсca and Number
- Antimatter Ray Clearcutting uva11008
- Minimum Depth of Binary Tree
- Hibernate ORM入门03
- CodeForces 615 A. Bulbs(水~)
- Comparing Two Long Integers
- YII url美化管理
- 从数组谈队列
- 【hdu5015】233 Matrix——矩阵快速幂
- Ubuntu unity 桌面正常工作在VNC上
- 【BZOJ2741】FOTILE模拟赛 L
- oracle中使用物化视图实现表的同步
- Mac OS X 下开启PHP
- ACDream 1024:Triangles