CodeForces 616A Comparing Two Long Integers【字符串】
2016-04-07 11:01
537 查看
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/printf instead of cin/cout in
C++, prefer to use BufferedReader/PrintWriterinstead 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
output
input
output
input
output
input
output
input
output
题意:
给出两个有前导零的大数,判断两者的大小关系
题解:
比较的时候需要跳过前导零,使用指针比较方便,注意是是大数的比较,先比较位数,位数相同的话,直接按位比较就行了..
/* http://blog.csdn.net/liuke19950717 */
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;
const int maxn=1e6+5;
char a[maxn],b[maxn];
void change(char *&p)//去掉前导零的操作
{
while(*p=='0')
{
++p;
}
}
char slove()
{
char *pa=a,*pb=b;
change(pa);change(pb);
int lena=strlen(pa),lenb=strlen(pb);
if(lena==lenb)//位数相同
{
int tp=strcmp(pa,pb);
if(tp==0)
{
return '=';
}
else if(tp==1)
{
return '>';
}
else
{
return '<';
}
}
else if(lena<lenb)
{
return '<';
}
return '>';
}
int main()
{
while(~scanf("%s%s",a,b))
{
printf("%c\n",slove());
}
return 0;
}
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/printf instead of cin/cout in
C++, prefer to use BufferedReader/PrintWriterinstead 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
>
题意:
给出两个有前导零的大数,判断两者的大小关系
题解:
比较的时候需要跳过前导零,使用指针比较方便,注意是是大数的比较,先比较位数,位数相同的话,直接按位比较就行了..
/* http://blog.csdn.net/liuke19950717 */
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;
const int maxn=1e6+5;
char a[maxn],b[maxn];
void change(char *&p)//去掉前导零的操作
{
while(*p=='0')
{
++p;
}
}
char slove()
{
char *pa=a,*pb=b;
change(pa);change(pb);
int lena=strlen(pa),lenb=strlen(pb);
if(lena==lenb)//位数相同
{
int tp=strcmp(pa,pb);
if(tp==0)
{
return '=';
}
else if(tp==1)
{
return '>';
}
else
{
return '<';
}
}
else if(lena<lenb)
{
return '<';
}
return '>';
}
int main()
{
while(~scanf("%s%s",a,b))
{
printf("%c\n",slove());
}
return 0;
}
相关文章推荐
- PS教程!教你快速简单打造一个元气满满的彩虹糖果字效
- iOS9出来了,http不管用
- zz 【转载用于学习】IOS开发技巧--Git的使用
- 欢迎使用CSDN-markdown编辑器
- Python Decorator 的来龙
- springmvc 页面和后台传值乱码问题
- CSS 的命名和书写
- android多媒体开发笔记
- gitignore忽略规则
- c++实验3-个人所得税计算器
- 深度XP完美精简版 (适合低配置电脑)——迅雷
- 蓝牙cc2540 开发问题
- 学习C语言,为了让自己变得更好
- iOS学习笔记--瀑布流封装
- C++第3次上机实验-个人所得税计算器
- C++实验4
- 4.4 single_server.c,multi_server.c,trigger_server.c:业务模块服务模板
- 删除链表中全部值为k的节点
- curl 详解
- 多重继承时的虚函数表