Educational Codeforces Round 5 A. Comparing Two Long Integers

 

A. Comparing Two Long Integers
time limit per test
2 seconds
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/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 "=".

Examples
input
9
10
output
<
input
11
10
output
>
input
00012345
12345
output
=
input
0123
9
output
>
input
0123
111
output
>

 字符串,去掉前面的零,比较大小,水题。

 

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <string>
 6 using namespace std;
 7 typedef long long ll;
 8 typedef unsigned long long ull;
 9 typedef long double ld;
10 
11 int main()
12 {
13     char a[1000005];
14     char b[1000005];
15     cin >> a;
16     cin >> b;
17     int lena,lenb;
18     int i,j;
19     for(i = 0; a[i] == '0'; i++);
20     for(j = 0; b[j] == '0'; j++);
21     lena = strlen(a)-i;
22     lenb = strlen(b)-j;
23     if(lena == 0 && lenb == 0)
24     {
25         cout << '=';
26         return 0;
27     }
28     else if(lena > lenb)
29         cout << '>';
30     else if(lena < lenb)
31         cout << '<';
32     else
33     {
34         int count = 0;
35         int k = strlen(a);
36         for(int m = i, n = j;m < k; m++, n++)
37         {
38             int p = a[m] - '0';
39             int q = b[n] - '0';
40             if(p == q)
41             {
42                 count = 1;
43                 continue;
44             }
45             else if(p > q)
46             {
47                 count = 0;
48                 cout << '>';
49                 break;
50             }
51             else
52             {
53                 count = 0;
54                 cout << '<';
55                 break;
56             }
57         }
58         if(count)
59         {
60             cout << '=';
61         }
62     }
63     
64     return 0;
65 }
View Code

 

转载于:https://www.cnblogs.com/Mino521/p/5727678.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值