HDU1047 Integer Inquiry
2015-07-16 20:17
645 查看
//注意输入判断与和的最终位数
Integer Inquiry
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)
Input
The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
The final input line will contain a single zero on a line by itself.
Output
Your program should output the sum of the VeryLongIntegers given in the input.
Sample Input
Sample Output
代码如下::
Integer Inquiry
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)
Input
The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
The final input line will contain a single zero on a line by itself.
Output
Your program should output the sum of the VeryLongIntegers given in the input.
Sample Input
123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0
Sample Output
370370367037037036703703703670
代码如下::
#include <cstdio> #include <cstring> using namespace std; #define Max 10000+5 char s[105]; short int sum[Max]; int main() { int len = 0,slen=0; int i; int m; memset(sum,0,sizeof(sum)); while(scanf("%s",s) && strcmp(s,"0")){ len = strlen(s)-1; for(i=0; len>=0; len--,i++){ m = sum[i]+s[len]-'0'; sum[i] = m%10; int j = i+1; sum[j] += m/10; if(j > slen && sum[j]!=0) slen = j;//这里没有加就一直错。。。。 while(sum[j] >= 10){ sum[j] = 0; j++; sum[j]++; if(j > slen) slen = j; } } } for(; slen>=0; slen--) printf("%d",sum[slen]); return 0; }
相关文章推荐
- UI移动设备屏幕知识
- [LeetCode][Java] Permutation Sequence
- POJ 1432 Decoding Morse Sequences
- 浅谈 qmake 之 shadow build
- algorithm之unique
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- UVa136 priority_queue优先队列
- StringBuffer,StringBuilder,数组常见操作,Arrays,基本类型包装类--2
- How do I sort an array of hashes by a value in the hash?
- IOS键盘的相关设置(UITextfield)
- UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
- [leedcode 95] Unique Binary Search Trees
- HDU 4632 Palindrome subsequence(区间DP 回文子串的个数)
- codeforces 558 D Guess Your Way Out! II
- 前端图像 裁剪利器 JQuerJjcrop+裁剪图像保存教程
- StringBuffer,StringBuilder,数组常见操作,Arrays,基本类型包装类--1
- UI_Block传值
- UIView 坐标转换
- 2015UESTC 暑假集训总结
- 测试[ uinon_struct ]