您的位置:首页 > 其它

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
10
Output
<
Input
11
10
Output
>
Input
00012345
12345
Output
=
Input
0123
9
Output
>
Input
0123
111
Output
>
模拟题,比较有前导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;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: