cf 616A Comparing Two Long Integers

问题描述

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/printf instead 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 "=".


样例输入

Input
9
10
Output
<
Input
11
10
Output
>
Input
00012345
12345
Output
=
Input
0123
9
Output
>
Input
0123
111
Output
>


代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

char a[1000005],b[1000005];

int main()
{
    scanf("%s",&a);
    scanf("%s",&b);
    int len1=strlen(a);
    int len2=strlen(b);
    int ii=0,jj=0;
    while(a[ii]=='0')ii++;
    while(b[jj]=='0')jj++;
    if(len1-ii>len2-jj)
        printf("%c\n",'>');
    else if(len1-ii<len2-jj)
        printf("%c\n",'<');

    else
        {
            for(;ii<len1;ii++,jj++)
            {
                if(a[ii]<b[jj])
                {
                    printf("%c\n",'<');
                    break;
                }

                else if(a[ii]>b[jj])
                {
                    printf("%c\n",'>');break;
                }

            }
            if(ii==len1)
                printf("%c\n",'=');
        }
}


你可能感兴趣的:(cf 616A Comparing Two Long Integers)