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;
    }
  • 相关阅读:
    结对编程项目作业3
    团队编程项目作业1-成员简介及分工
    团队编程项目作业1-需求分析
    结对编程项目作业1
    20171123-构建之法:现代软件工程-阅读笔记
    课后作业-阅读任务-阅读提问-4
    软件工程课程总结
    结对编程项目五子棋-结对项目总结
    课后作业-阅读任务-阅读笔记-1
    结对编程项目作业3
  • 原文地址:https://www.cnblogs.com/homura/p/5124832.html
Copyright © 2011-2022 走看看