CodeForces 616A
来源:互联网 发布:linux 替换jar包文件 编辑:程序博客网 时间:2024/06/09 17:18
You are given two very long integers a, b (leading zeroes are allowed). You should check what numbera 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 usescanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead ofScanner/System.out in Java. Don't use the function input() inPython2 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 than106 digits.
Print the symbol "<" ifa < b and the symbol ">" ifa > b. If the numbers are equal print the symbol "=".
910
<
1110
>
0001234512345
=
01239
>
0123111
>
模拟题,比较有前导0的两数的大小。
思路:跳过前导0,先比较长度,长度相等再一位一位的比较。
#include<iostream>#include<cstdio>#include<string>using namespace std;string s1,s2;char ss[1000005];int main(){ while(scanf("%s",&ss)!=EOF) { s1=ss; scanf("%s",&ss); s2=ss; int len1=s1.length(),len2=s2.length(); int p1=0,p2=0; while(s1[p1]=='0'&&p1<len1) p1++; while(s2[p2]=='0'&&p2<len2) p2++; if(len1-p1>len2-p2) {printf(">\n");continue;} else if(len1-p1<len2-p2) {printf("<\n");continue;} int i; bool flag=false; for(i=p1;i<len1;i++) { if(s1[i]>s2[i-p1+p2]) {printf(">\n");flag=true;break;} if(s1[i]<s2[i-p1+p2]) {printf("<\n");flag=true;break;} } if(!flag) printf("=\n"); } return 0;}
- Codeforces 616A
- CodeForces 616A
- 【CodeForces】616A
- CodeForces-a
- Codeforces 903A A
- 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 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- MD5加密算法的Java实现
- oc学习之Foundation框架--NSSet类
- css动画
- 什么是Activity
- 面试问题汇总
- CodeForces 616A
- 221. Maximal Square(难)
- awk、cut、sort和uniq
- cocos2d-x-3.0学习笔记之如何添加菜单按钮
- python之显示按键操作
- M101P: MongoDB for Developers - Chapter 1: Introduction
- 【JZ雅礼联考】跳楼机 题解
- ListView复用导致checkBox错乱的解决方法
- Linux 共享库加载方法