CodeForces 616A Comparing Two Long Integers【字符串】
来源:互联网 发布:网络加速的原理 编辑:程序博客网 时间:2024/06/07 10:01
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().
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 "=".
910
<
1110
>
0001234512345
=
01239
>
0123111
>
给出两个有前导零的大数,判断两者的大小关系
题解:
比较的时候需要跳过前导零,使用指针比较方便,注意是是大数的比较,先比较位数,位数相同的话,直接按位比较就行了..
/*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;}
- CodeForces 616A Comparing Two Long Integers【字符串】
- CodeForces 616A Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- CodeForces 616 A. Comparing Two Long Integers(水~)
- day4 CodeForces 616A Comparing Two Long Integers
- CodeForce 616A Comparing Two Long Integers 字符串比较
- CF Comparing Two Long Integers 616A
- cf 616A Comparing Two Long Integers
- A. Comparing Two Long Integers
- Educational Codeforces Round 5 A. Comparing Two Long Integers
- Codeforces--616A--Comparing Two Long Integers(模拟水题)
- CodeForces - 616A Comparing Two Long Integers (模拟)比较两个数大小
- Comparing Two Long Integers
- Educational Codeforces Round 5-A. Comparing Two Long Integers(模拟)
- Educational Codeforces Round 5 A. Comparing Two Long Integers (水)
- Codeforces 872 A Search for Pretty Integers
- PowerDesigner(八)-面向对象模型(用例图,序列图,类图,生成Java源代码及Java源代码生成类图)
- sed命令详解
- C++指针与引用的区别
- 蓝桥杯b组c++.9.交换杯子
- 山西省蓝桥B9
- CodeForces 616A Comparing Two Long Integers【字符串】
- [Contiki系列论文之2]WSN的自适应通信架构
- 深入理解jQuery插件开发
- 简历无亮点?应用之星教你72变!
- c++作业3
- c++第三次实验
- PowerDesigner(九)-模型文档编辑器(生成项目文档)
- BZOJ 2683 简单题(CDQ分治+容斥)
- Tomcat中监控JVM内存使用情况