大数系列——Integer Inquiry
2013-03-23 23:16
211 查看
Integer Inquiry |
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy werehere to see theseresults.'' (Chip moved to a new apartment, once one became available onthe third floor of theLemon Sky apartments on Third Street.)
Input
The input will consist of at most 100 lines of text, each of whichcontains a single VeryLongInteger.Each VeryLongInteger will be 100 or fewer characters in length, and willonly 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
字符串系列刷得实在蛋疼,先换大数系列刷刷。。。
第一题很水,不愧是大数。
大数相加,倒序输入数组再逐位计算,再倒序输出。
AC代码:
#include<iostream> #include<string> using namespace std; int main() { int a[100] = {0}, sum[110] = {0}; string str; while (1) { cin >> str; if (str[0] == '0') break; for (int i = 0; i < (int)str.size(); i++) a[i] = str[(int)str.size() - i - 1] - '0'; for (int i = 0; i < (int)str.size(); i++) { int temp = a[i] + sum[i]; sum[i] = temp % 10; sum[i + 1] += temp / 10; } } int i; for (i = 100; i >= 0; i--) if (sum[i]) break; for (;i >= 0; i--) cout << sum[i]; cout << endl; return 0; }
相关文章推荐
- 大数系列——Integer Inquiry
- HD-ACM算法专攻系列(12)——Integer Inquiry
- UVA oj 练习水题 算法入门经典(大数系列)
- Integer Inquiry(大数加法)
- POJ-1001 求高精度幂-大数乘法系列
- Integer Inquiry(大数加法)
- 系列文章-大数阶算之计算从入门到精通(序)
- Integer Inquiry_hdu_1047(大数).java
- HDU 1047 多个大数相加 Integer Inquiry
- 杭电OJ(HDOJ)1047题:Integer Inquiry(大数操作——加运算)
- 大数系列——大数除法以及求模
- 九度OJ 1119:Integer Inquiry(整数相加) (大数运算)
- 大数系列——大数加法
- 九度OJ 1119:Integer Inquiry(整数相加) (大数运算)
- hdu 4523 威威猫系列故事——过生日(简单大数相加比较)
- hdu 4523 威威猫系列故事——过生日(简单大数相加比较)
- 面试100题系列之13大数的四则运算
- 大数系列——大数减法
- 面试100题系列之13大数的四则运算
- 大数系列——大数乘法