cf 616A Comparing Two Long Integers
2016-01-22 10:57
176 查看
问题描述
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().
输入
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.
输出
Print the symbol "<" if
a < b and the symbol ">" if
a > b. If the numbers are equal print the symbol "=".
样例输入
Input
Output
Input
Output
Input
Output
Input
Output
Input
Output
代码如下:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;
char a[1000005],b[1000005];
int main()
{
scanf("%s",&a);
scanf("%s",&b);
int len1=strlen(a);
int len2=strlen(b);
int ii=0,jj=0;
while(a[ii]=='0')ii++;
while(b[jj]=='0')jj++;
if(len1-ii>len2-jj)
printf("%c\n",'>');
else if(len1-ii<len2-jj)
printf("%c\n",'<');
else
{
for(;ii<len1;ii++,jj++)
{
if(a[ii]<b[jj])
{
printf("%c\n",'<');
break;
}
else if(a[ii]>b[jj])
{
printf("%c\n",'>');break;
}
}
if(ii==len1)
printf("%c\n",'=');
}
}
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().
输入
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.
输出
Print the symbol "<" if
a < b and the symbol ">" if
a > b. If the numbers are equal print the symbol "=".
样例输入
Input
9 10
Output
<
Input
11 10
Output
>
Input
00012345 12345
Output
=
Input
0123 9
Output
>
Input
0123 111
Output
>
代码如下:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;
char a[1000005],b[1000005];
int main()
{
scanf("%s",&a);
scanf("%s",&b);
int len1=strlen(a);
int len2=strlen(b);
int ii=0,jj=0;
while(a[ii]=='0')ii++;
while(b[jj]=='0')jj++;
if(len1-ii>len2-jj)
printf("%c\n",'>');
else if(len1-ii<len2-jj)
printf("%c\n",'<');
else
{
for(;ii<len1;ii++,jj++)
{
if(a[ii]<b[jj])
{
printf("%c\n",'<');
break;
}
else if(a[ii]>b[jj])
{
printf("%c\n",'>');break;
}
}
if(ii==len1)
printf("%c\n",'=');
}
}
相关文章推荐
- Activiti中的流程历史保存流程发起人的方法
- C# 五种加密方式
- Excel 导入 Sql Server出错——“文本被截断,或者一个或多个字符在目标代码页中没有匹配项”错误的解决
- jqGrid配置属性说明
- spring data jpa hibernate jpa 三者之间的关系
- jenkins配置及使用中出现的问题
- 如何重置CentOS7的Root密码
- python 学习笔记3
- OneAlert 入门(二)——事件分析
- C语言域名解析的简单实现
- C语言域名解析的简单实现
- C语言域名解析的简单实现
- 手机端样式初始化css
- Spring事务管理与数据库隔离级别的关系(Spring+mysql)
- 中国象棋,马不重复的走完每一格
- POJ2533 Longest ordered subsequence
- 曾经的中国互联网:多少巨头销声匿迹
- STM8的IAP在线升级
- 负载均衡之Nginx的安装
- HACK的写法