Integer Inquiry(大数加法)
2013-12-15 15:37
281 查看
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 <stdio.h> void pri (void); char a[1000]; int num[10000]; int main() { char *head = NULL,*p1 = NULL; int i = 9999; while (gets (a),a[0] != '0') { head = a; p1 = a; while (*p1 != '\0') p1++; p1--; i = 9999; while (p1 >= head) { num[i] += (int)(*p1 - '0'); i--; p1--; } } i = 9999; while (i >= 0) { if (num[i] >= 10) { num[i - 1] += (int)(num[i] / 10); num[i] = num[i] % 10; } i--; } pri (); return 0; } void pri (void) { int tf = 0; int i = 0; while (i < 10000) { if ((!tf) && num[i] != 0) tf = 1; if (tf) { printf ("%d",num[i]); } i++; } printf ("\n"); }
相关文章推荐
- Integer Inquiry 大数加法
- Integer Inquiry(大数加法)
- 大数模板 大数加法,大数减法,大数乘法,大数除法,大数比较等操作
- 1005 大数加法(java写大数问题真有优势)
- 大数加法 big number add
- 大数系列——大数加法
- 高精度大数加法
- hdu 1502 Regular Words(java大数加法+dp)
- NYOJ 880 A+B Problem II(大数加法)
- 大数加法 hdu 1002
- 大数的加法和乘法,高精度
- 大数加法(递推)
- How Many Fibs? 大数加法
- 51nod 1005 大数加法(可为负数)
- UVA_10183||POJ_2413||ZOJ_1962||HDU_1316(大数加法、检索)
- HDU-1002-大数加法
- C++实现大数的加法
- 大数加法字符串版本
- Java常用数字工具类 大数乘法、加法、减法运算(2)
- 用数组实现大数加法