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;
    }
  • 相关阅读:
    easyui属性表格的一点小总结
    我是程序员:国庆带女朋友回家见父母
    我睁着朦胧呆滞的双眼立在初秋的夜里
    iframe父子兄弟之间调用传值(contentWindow && parent)
    向前兼容和向后兼容的含义
    char 与 String 相等比较
    2012国庆12天的长假
    JavaScript遍历XML总结
    Spring3.x企业应用开发实战Spring+Hibernat架构分析
    w3school上系统过了一遍Jquery的总结
  • 原文地址:https://www.cnblogs.com/homura/p/5124832.html
Copyright © 2011-2022 走看看