Codeforces--616A--Comparing Two Long Integers(模拟水题)
2016-04-05 17:29
441 查看
Comparing Two Long Integers
Submit Status
Description
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 useBufferedReader/PrintWriter instead
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 "=".
Sample Input
Input
Output
Input
Output
Input
Output
Input
Output
Input
Output
>#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<map>#include<stack>#include<queue>#include<math.h>#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 1000010
#define M 1000000007
using namespace std;
char a
,b
;
char x
,y
;
int main()
{
int t,n,m,i,j,k;
while(scanf("%s%s",a,b)!=EOF)
{
int aa=0,bb=0,la,lb,ka,kb;
la=strlen(a);lb=strlen(b);
bool fa=false,fb=false;
if(strcmp(a,b)==0)
{
printf("=\n");
continue;
}
for(i=0;i<la;i++)
{
if(a[i]=='0')
{
aa=i;
fa=true;
continue;
}
else
break;
}
for(i=0;i<lb;i++)
{
if(b[i]=='0')
{
bb=i;
fb=true;
continue;
}
else
break;
}
if(fa) aa++;
if(fb) bb++;
ka=0;kb=0;
for(i=aa;i<la;i++)
x[ka++]=a[i];
for(i=bb;i<lb;i++)
y[kb++]=b[i];
if(ka>kb)
printf(">\n");
else if(ka<kb)
printf("<\n");
else
{
if(strcmp(x,y)>0)
printf(">\n");
else if(strcmp(x,y)==0)
printf("=\n");
else
printf("<\n");
}
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
memset(x,'\0',sizeof(x));
memset(y,'\0',sizeof(y));
}
return 0;
}
Time Limit: 2000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
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 useBufferedReader/PrintWriter instead
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 "=".
Sample Input
Input
9 10
Output
<
Input
11 10
Output
>
Input
00012345 12345
Output
=
Input
0123 9
Output
>
Input
0123 111
Output
>#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<map>#include<stack>#include<queue>#include<math.h>#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 1000010
#define M 1000000007
using namespace std;
char a
,b
;
char x
,y
;
int main()
{
int t,n,m,i,j,k;
while(scanf("%s%s",a,b)!=EOF)
{
int aa=0,bb=0,la,lb,ka,kb;
la=strlen(a);lb=strlen(b);
bool fa=false,fb=false;
if(strcmp(a,b)==0)
{
printf("=\n");
continue;
}
for(i=0;i<la;i++)
{
if(a[i]=='0')
{
aa=i;
fa=true;
continue;
}
else
break;
}
for(i=0;i<lb;i++)
{
if(b[i]=='0')
{
bb=i;
fb=true;
continue;
}
else
break;
}
if(fa) aa++;
if(fb) bb++;
ka=0;kb=0;
for(i=aa;i<la;i++)
x[ka++]=a[i];
for(i=bb;i<lb;i++)
y[kb++]=b[i];
if(ka>kb)
printf(">\n");
else if(ka<kb)
printf("<\n");
else
{
if(strcmp(x,y)>0)
printf(">\n");
else if(strcmp(x,y)==0)
printf("=\n");
else
printf("<\n");
}
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
memset(x,'\0',sizeof(x));
memset(y,'\0',sizeof(y));
}
return 0;
}
相关文章推荐
- 如何安装Android Studio
- 【BZOJ1143】[CTSC2008]祭祀river【最长反链】【传递闭包】
- Maven的安装和配置——在Windows上安装Maven
- 在Ubuntu 14.04 64bit上安装lua5.2
- Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/rel
- Android BitmapShader 实战 实现圆形、圆角图片
- Messenger/Handler and Binder
- .gitignore详解
- 基于 Lind.DDD 的 权限管理系统
- 《构建之法》第四章读后感
- jquery 离开页面提示信息
- HDOJ 1222 Wolf and Rabbit(判断互质,水)
- XMPP 通讯原语
- Webservice工作原理及实例
- 面试题整理 二
- Oracle -- 默认用户
- 知识体系总结
- Android开源项目分类汇总
- linux下JDK安装与主机名设定
- CodeForces 618B-Guess the Permutation【搜索】