CodeForces 616A Comparing Two Long Integers

来源:互联网 发布:阿里云ssh登录 编辑:程序博客网 时间:2024/06/07 18:27

A. Comparing Two Long Integers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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().

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.

Output

Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".

Sample test(s)
input
910
output
<
input
1110
output
>
input
0001234512345
output
=
input
01239
output
>
input
0123111
output
>

去掉前导0,然后比较长度,长度相等再一位一位比较


#include <iostream>#include<cstdio>#include<cstring>#define maxn 10000010using namespace std;char a[maxn],b[maxn];int main(){    while(~scanf("%s%s",a,b))    {        int lena=strlen(a);        int lenb=strlen(b);        int i=0,j=0;        while(i<lena&&a[i]=='0')            i++;        while(j<lenb&&b[j]=='0')            j++;        if(lena-i>lenb-j)        {            printf(">\n");            continue;        }        else if(lena-i<lenb-j)        {            printf("<\n");            continue;        }        while(i<lena&&j<lenb)        {            if(a[i]>b[j])            {                printf(">\n");                break;            }            else if(a[i]<b[j])            {                printf("<\n");                break;            }            else                i++,j++;        }        if(i==lena&&j==lenb)            printf("=\n");    };    return 0;}


0 0
原创粉丝点击