CodeForces 616A
2016-08-21 17:04
162 查看
A. Comparing Two Long Integerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two very long integersa, 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 ofcin/cout in C++, prefer to use BufferedReader/PrintWriter instead ofScanner/System.out inJava. Don't use the function input() inPython2 instead of it use the functionraw_input().InputThe first line contains a non-negative integera.The second line contains a non-negative integerb.The numbers a, b may contain leading zeroes. Each of them contains no more than106 digits.OutputPrint the symbol "<" ifa < b and the symbol ">" ifa > b. If the numbers are equal print the symbol "=".ExamplesInput
9 10Output
<Input
11 10Output
>Input
00012345 12345Output
=Input
0123 9Output
>Input
0123 111Output
>
模拟题,比较有前导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 494B Obsessive String
- CodeForces 606 B. Testing Robots(水~)
- CodeForces 510C (拓扑排序)
- CodeForces 596 B. Wilbur and Array(贪心)
- codeforces 182E Wooden Fence(方案数DP)【模板】
- Codeforces-686D-Kay and Snowflake
- Codeforces 509E. Pretty Song
- Codeforces 627A XOR Equation 【数学】
- Codeforces-----510B Fox And Two Dots 搜索
- codeforces 839B(模拟)
- CodeForces - 192A Funky Numbers ——二分
- codeforces 213C Relay Race(dp)
- codeforces 632D. Longest Subsequence 筛法
- CodeForces 680A Bear and Five Cards(取数字)
- Codeforces 839B Game of the Rows 贪心
- 【CodeForces - 919E】 Congruence Equation 【费马小定理 + 思维】
- CodeForces 508D(Codeforces Round #288 (Div. 2))Tanya and Password
- codeforces 632D