CodeForces 616A 大数的比较 字符串的使用
来源:互联网 发布:java二次开发平台 编辑:程序博客网 时间:2024/06/06 09:43
Comparing Two LongIntegers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Youare given two very long integers a, b (leadingzeroes are allowed). You should check what number a or b isgreater or determine that they are equal.
Theinput 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.
Asinput/output can reach huge size it is recommended to use fast input/outputmethods: for example, prefer to use scanf/printfinsteadof cin/cout inC++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.Don't use the function input() in Python2 insteadof it use the function raw_input().
Input
Thefirst line contains a non-negative integer a.
Thesecond line contains a non-negative integer b.
Thenumbers a, b may containleading zeroes. Each of them contains no more than 106 digits.
Output
Printthe symbol "<" if a < b andthe symbol ">" if a > b.If the numbers are equal print the symbol "=".
Examples
input
9
10
output
<
input
11
10
output
>
input
00012345
12345
output
=
input
0123
9
output
>
input
0123
111
output
>
题意:就是两个非负大整数比较大小。
思路:去掉前面的 0 即可,应该熟练使用字符串类函数
代码:
/*=============================AC情况===============================*//*题目网址: *//*时间: *//*心得: 掌握strlen(),strcmp()的参数意义 */#include<stdio.h>#include<stdlib.h>#include<string.h>#define G 1000013int main() {char a[G],b[G];int la,lb;scanf("%s",a);int ka=0;while(a[ka]=='0')ka++;la=strlen(a+ka);scanf("%s",b);int kb=0;while(b[kb]=='0')kb++;lb=strlen(b+kb);if(la>lb) printf(">\n");else if(la<lb)printf("<\n");else {if(strcmp(a+ka,b+kb)<0) printf("<\n");if(strcmp(a+ka,b+kb)==0) printf("=\n");if(strcmp(a+ka,b+kb)>0) printf(">\n");}return 0;}/*********************************测试数据***********************************************************************************************************/
第117组测试数据错误(超时)代码:
#include<stdio.h>#include<stdlib.h>#include<string.h>#define G 1000001 int main() {char a[G],b[G];char a2[G],b2[G];int la,lb,ca,cb;scanf("%s",a);scanf("%s",b);la=strlen(a);lb=strlen(b);int k=0;while(a[k]=='0')k++;ca=la-k;for(int j=k,l=0; j<la; j++,l++)a2[l]=a[j];k=0;while(b[k]=='0')k++;cb=lb-k;for(int j=k,l=0; j<lb; j++,l++)b2[l]=b[j];//printf("%d %d",ca,cb);if(ca>cb) printf(">\n");else if(ca<cb)printf("<\n");else {if(strcmp(a2,b2)<0) printf("<\n");if(strcmp(a2,b2)==0) printf("=\n");if(strcmp(a2,b2)>0) printf(">\n");}return 0;}
- CodeForces 616A 大数的比较 字符串的使用
- java 大数的比较
- 大数的a+b
- 字符串与大数比较
- 大数的四则运算与比较
- 分割 (大数的分割) 字符串的灵活使用
- Codeforces 232A Cycles 比较有趣的思路题
- 大数的运算实现(C++、字符串)、Git使用示例
- 大数加法的字符串实现
- Java大数的使用
- codeforces愚人节2013 a一个谜一样的字符串
- 关于使用equals比较字符串的问题
- 字符串的构建和使用,字符串的拷贝和比较
- CodeForces 522A A. Reposts Map容器的使用
- BFS:HDU2054-A==B?(字符串的比较)
- 大数的幂 POJ AC 比较粗糙
- 大数相乘的两种算法比较
- 大数相乘-写的比较麻烦
- SlidingMenu的配置
- 《剑指offer》:[31]连续子数组的最大和及子序列的值
- Java中常见编码格式
- Android App解决卡顿慢之内存抖动及内存泄漏(发现和定位)
- hdu 5706 GirlCat(dfs)
- CodeForces 616A 大数的比较 字符串的使用
- Android XML解析
- jps命令使用
- 20160609常规赛总结
- Android AsyncTask 应用
- AndroidStudio常用快捷键
- php笔记(11)——json_encode后中文编码问题
- ArcGIS连接局域网另一台电脑上的SQLServer数据库
- [转]Linux GCC常用命令