You are given two very long integers a, b (leading zeroes are allowed). You should check what number a 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 use scanf/printfinstead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_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 than 106 digits.
Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".
9 10
<
11 10
>
00012345 12345
=
0123 9
>
0123 111
>
解题思路:用两个字符串存储输入的整数,然后去掉前导零,进行比较。去掉前导零后,若串a长于串b,则输出">";若串a短于串b,则输出"<";若串a长度等于串b,则从最高位开始逐位进行比较。
代码如下:
#include <cstdio>
#include <cstring>
#include <cstdlib>
const int maxn = 1000005;
char a[maxn],b[maxn];
int main()
{
int i,j,k;
while(scanf("%s %s",a,b) != EOF){
int lena = strlen(a);
int lenb = strlen(b) ;
for(i = 0;i < lena;i++){
if(a[i] == '0')
continue;
if(a[i] != '0')
break;
}
//printf("i = %d\n",i);
lena -= i;
//printf("lena = %d\n",lena);
for(j = 0;j < lenb;j++){
if(b[j] == '0')
continue;
else
break;
}
//printf("j = %d\n",j);
lenb -= j;
//printf("lenb = %d\n",lenb);
int posa,posb;
if(lena == lenb){
for(posa = i,posb = j;posa < lena + i && posb < lenb + j;posa++,posb++){
if(a[posa] == b[posb]){
continue;
}else if(a[posa] > b[posb]){
printf(">\n");
break;
}else{
printf("<\n");
break;
}
}
if(posa == lena + i && posb == lenb + j)
printf("=\n");
}else if(lena > lenb){
printf(">\n");
}else{
printf("<\n");
}
}
return 0;
}