Educational Codeforces Round 5 A. Comparing Two Long Integers (水)

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

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
9
10
Output
<
Input
11
10
Output
>
Input
00012345
12345
Output
=
Input
0123
9
Output
>
Input
0123
111
Output
>

题意:给你两个数,比较大小


思路:数字很大,字符串存储,去掉前导零,比较大小


ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1001000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define mod 1000000007
using namespace std;
char a[MAXN],b[MAXN];
char c[MAXN],d[MAXN];
int main()
{
    int i;
    while(scanf("%s%s",a,b)!=EOF)
    {
        int bz=0;
        int len=strlen(a);
        mem(c);mem(d);
        int cnt=0;
        for(i=0;i<len;i++)
        {
            if(a[i]!='0')
            {
                bz=1;
                c[cnt++]=a[i];
            }
            else
            {
                if(bz)
                c[cnt++]=a[i];
            }
        }
        len=strlen(b);bz=0;cnt=0;
        for(i=0;i<len;i++)
        {
            if(b[i]!='0')
            {
                bz=1;
                d[cnt++]=b[i];
            }
            else
            {
                if(bz)
                d[cnt++]=b[i];
            }
        }
        //printf("%s %s\n",c,d);
        int len1=strlen(c);
        int len2=strlen(d);
        if(len1>len2)
        printf(">\n");
        else if(len1<len2)
        printf("<\n");
        else
        {
            int k=strcmp(c,d);
            if(k==0)
            printf("=\n");
            else if(k<0)
            printf("<\n");
            else
            printf(">\n");
        }
    }
    return 0;
}



你可能感兴趣的:(Educational Codeforces Round 5 A. Comparing Two Long Integers (水))