zoukankan      html  css  js  c++  java
  • Codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers 高精度比大小,模拟

    A. Comparing Two Long Integers

    题目连接:

    http://www.codeforces.com/contest/616/problem/A

    Description

    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 Input

    9
    10

    Sample Output

    <

    Hint

    题意

    给你两个带前导0的高精度数字,然后让你比大小。

    题解:

    模拟一下就好了,首先看数位,然后再看每一位的数字就行了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    string a,b;
    int main()
    {
        cin>>a>>b;
        int len1 = a.size(),len2 = b.size();
        int la = 0,lb = 0;
        while(a[la]=='0'&&la<len1)la++;
        while(b[lb]=='0'&&lb<len2)lb++;
        if(len1-la>len2-lb)return puts(">");
        if(len1-la<len2-lb)return puts("<");
        for(int i=la;i<len1;i++)
        {
            if(a[i]>b[i-la+lb])return puts(">");
            if(a[i]<b[i-la+lb])return puts("<");
        }
        return puts("=");
    }
  • 相关阅读:
    Unity周记: 2020.09.07-09.13
    Unity周记: 2020.08.31-09.06
    CF1060F Shrinking Tree
    洛谷P6783 [Ynoi2008] rrusq
    洛谷P5644 [PKUWC2018] 猎人杀
    洛谷P1587 [NOI2016] 循环之美
    洛谷P4466 [国家集训队] 和与积
    集合幂级数杂题
    Flink基础(49):FLINK SQL(25) 内置函数(七)表值函数
    Flink基础(48):FLINK SQL(24) 内置函数(六)条件函数
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5127072.html
Copyright © 2011-2022 走看看