CodeForces 616A Comparing Two Long Integers

来源:互联网 发布:中国科技实力 知乎 编辑:程序博客网 时间:2024/06/06 20:25

题目:

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/printfinstead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the functioninput() 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

Input
910
Output
<
Input
1110
Output
>
Input
0001234512345
Output
=
Input
01239
Output
>
Input
0123111
Output
>

就是比较2个整数的大小,很简单。

主要就是c语言不熟悉。

代码:

#include<stdio.h>#include <stdlib.h> #include<string.h>int main(){char*s1 = new char[1000000];char*s2 = new char[1000000];int l1, l2;char c;while (gets(s1)&&gets(s2)){l1 = strlen(s1);l2 = strlen(s2);int i = 0, j = 0;while (s1[i] == '0'&& l1){i++;l1--;}while (s2[j] == '0'&& l2){j++;l2--;}if (l1 > l2)c='>';else if (l1 < l2)c='<';else{while (s1[i]){if (s1[i]>s2[j]){c = '>';break;}if (s1[i]<s2[j]){c = '<';break;}i++;j++;l1--;}if (l1 == 0)c = '=';}printf("%c\n", c);}return 0;}

2 0
原创粉丝点击