zoukankan      html  css  js  c++  java
  • codeforces 616A Comparing Two Long Integers

    A. 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/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
    9
    10
    output
    <
    input
    11
    10
    output
    >
    input
    00012345
    12345
    output
    =
    input
    0123
    9
    output
    >
    input
    0123
    111
    output
    >
    #include<cstdio>
    #include<cstring>
    #include<stack>
    #include<iterator>
    #include<vector>
    #include<iostream>
    #include<map>
    #include<string>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn=1e6+5;
    int main()
    {
        int len[2];
        char s[2][maxn];
        for(int i=0;i<2;i++)
            scanf("%s",s[i]),len[i]=strlen(s[i]);
        int i,j;
        for(i=0;i<len[0];i++)
            if(s[0][i]!='0')break;
        for(j=0;j<len[1];j++)
            if(s[1][j]!='0')break;
        if(len[0]-i>len[1]-j)
            puts(">");
        else if(len[0]-i<len[1]-j)
            puts("<");
        else
        {
            for(;i<len[0];i++,j++)
                if(s[0][i]!=s[1][j])break;
            i==len[0]?puts("="):puts(s[0][i]>s[1][j]?">":"<");
        }
        return 0;
    }
  • 相关阅读:
    重构第30天 尽快返回 (Return ASAP)
    Thingsboard MQTT连接至服务器
    Thingsboard学习之三启动Thingsboard
    Thingsboard学习之二安装Docker和Docker-Compose
    Thingsboard学习之一CentOS安装系统更新
    CentOS 修改固定IP地址
    macbook配置homebrew
    macbook配置flutter环境变量
    Linux单独打包工具-Ubuntu
    postman测试API
  • 原文地址:https://www.cnblogs.com/homura/p/5124832.html
Copyright © 2011-2022 走看看