CodeForces 616A Comparing Two Long Integers
2016-07-24 09:00
225 查看
题目:
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
Output
Input
Output
Input
Output
Input
Output
Input
Output
就是比较2个整数的大小,很简单。
主要就是c语言不熟悉。
代码:
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
9 10
Output
<
Input
11 10
Output
>
Input
00012345 12345
Output
=
Input
0123 9
Output
>
Input
0123 111
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;
}
相关文章推荐
- Git使用教程
- linux服务器出现大量TIME_WAIT的解决方法
- poj 3468 线段树区间更新
- 防止表单重复提交
- c++
- Prime Ring Problem
- 【VS开发】免费打工仔:一个完善的ActiveX Web控件教程
- hdu 1112
- AT24C512与AT24C512B的区别
- POJ 3620 Avoid The Lakes(DFS)
- N皇后
- 让键盘不占空间和关闭软键盘的方法
- 【图像处理】ISP 图像传感器camera原理
- 前端基础问题整理-JavaScript相关(一)
- Python 3.4 链接mysql5.7 数据库使用方法
- mysql字符串拼接,存储过程
- netstat命令详解
- Java TCP客户端服务器端交互
- Android高效加载图片和缓存策略LRU,DiskLRU
- MySql使用(1)