poj_1503 大整数加法
2015-01-27 22:18
204 查看
两个细节要注意:
(1)、保存最终结果的数组要开102的大小!
(2)、存在001这样的数据!所以开始的判断要:if (!strcmp(s,"0"))
code:
(1)、保存最终结果的数组要开102的大小!
(2)、存在001这样的数据!所以开始的判断要:if (!strcmp(s,"0"))
code:
<span style="font-size:18px;">#include <iostream> #include <fstream> using namespace std; char s[101]; int ans[102]; int main() { fstream in("input.txt"); while (cin >> s) { if (!strcmp(s,"0")) break; int len = strlen(s); for (int i = 0; i<len; i++){ ans[i] += s[len - i - 1] - '0'; } for (int i = 0; i <= 101; i++){ if (ans[i] >= 10){ ans[i + 1] += ans[i] / 10; ans[i] %= 10; } } } int end = 101; while (ans[end] == 0) end--; for (int j = end; j >= 0; j--) cout << ans[j]; cout << endl; //system("pause"); return 0; } </span>
相关文章推荐
- 【原】 POJ 1503 Integer Inquiry 大整数加法 解题报告
- POJ 1503(高精度整数加法) 解题报告
- POJ 1503(高精度整数加法) 解题报告
- poj 1503 大整数高精度 加法
- POJ-1503-大整数加法
- POJ-1503-Integer Inquiry-大数加法
- 大数加法-poj-1503
- POJ--1503:Integer Inquiry 大数加法
- POJ 1503 大整数相加的问题
- POJ 1503 Integer Inquiry 高精度加法
- Poj 2981:大整数加法
- POJ 3378 (大整数加法+树状数组)
- POJ 1503 Integer Inquiry(高精度整数)
- 【大数加法】POJ-1503、NYOJ-103
- POJ 1503 Integer Inquiry 美丽的大整数相加 + 测试数据
- poj-1503 大整数运算
- 二分查找+大整数加法——Poj 2413 How many Fibs?
- poj 1503 高精度加法
- POJ 2981 大整数加法 解题报告
- POJ 2506 Tiling(递推+大整数加法)