2013资格赛——Another A+B
来源:互联网 发布:邯郸软件开发 编辑:程序博客网 时间:2024/05/22 10:22
Description
Calculate a + b.Input
The input will consist of a series of pairs of integers a and b(0<=a,b<=10^1000),separated by a space, one pair of integers per line.Output
For each pair of input integers a and b you should output the result of a + b in one line.Sample Input
2 3
Sample Output
5
分析:大数问题。注意细节,边界进位处理。
#include<stdio.h>#include<string.h>int main() { int n,i,l1,l2,max,a,j,t; char s1[1001],s2[1001],s3[1001]; while(~scanf("%s%s",s1,s2)) { getchar(); l1 = strlen(s1); l2 = strlen(s2); if(l1>l2) max = l1; else max = l2; t=max; memset(s3,'\0',1001); memset(s3,'0',max+1); l1 = l1-1; l2 = l2-1; s3[0]='0'; while(l1>=0 && l2>=0) { a = s1[l1--]-'0'+s2[l2--]-'0'+s3[max]-'0'; s3[max--] ='0'+a%10; if(a>=10) s3[max]+=1; } while(l1>=0) { a = s3[max]-'0'+s1[l1--]-'0'; s3[max--]='0'+a%10; if(a>=10) s3[max]+=1; } while(l2>=0) { a = s3[max]-'0'+s2[l2--]-'0'; s3[max--]='0'+a%10; if(a>=10) s3[max]+=1; } if(s3[0] > '0') printf("%c",s3[0]); for(j = 1;j < t; j++) printf( "%c", s3[j]); printf( "%c\n", s3[j]); if(i<n-1) printf("\n"); } return 0; }
- 2013资格赛——Another A+B
- 1001 - Another A+B
- Another A+B
- Another a+b FZU
- HUST 1001 Another A+B
- Yet another A + B——KTU Programming Camp (Day 1) I题
- 2013资格赛——ICPC
- 百度之星资格赛——B题
- 2016百度之星资格赛——B
- 西安电子Problem 1002 - another a+b
- Gym 100735 - I. Yet another A + B
- 【MS编程之美资格赛】Problem A及Problem B
- 2013资格赛——电话记录
- 2013资格赛——Binomial Showdown
- 2013资格赛——取石子游戏
- 2013资格赛——Next Round
- 2013资格赛——桃花群岛
- another a+b处理多组数据的输入
- 【转】光流Optical Flow介绍与OpenCV实现
- ACM主要内容
- SDRAM的地址映射方式BRC(Bank Row Column)和RBC(Row Bank Column)
- 2013 多校第九场 hdu 4696 Answers(纯YY )
- 分享一个.NET实现的简单高效WEB压力测试工具
- 2013资格赛——Another A+B
- 约瑟夫环 <list>
- LeetCode - Reverse Linked List II
- jQuery EasyUI 在datagrid上使用combotree 进行多选
- MATLAB对于文本文件(txt)数据读取的技巧总结(经典中的经典)
- 密码文本框不能正常取值的解决方案
- 数据结构之线性表顺序存储
- ruby on rails gems
- ubuntu root登入