【思路】:大数处理都一样。
【AC代码】:代码细节可以美化一下。
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> #include <iomanip> using namespace std; #define MAX 100+10 int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int a[MAX], b[MAX], i = 0, alen = 0, blen = 0; char str[MAX]; //initial memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); //input cin >> str; alen = strlen(str); for (i = 0; i < alen; i++) a[alen-1-i] = str[i]-'0'; cin >> str; blen = strlen(str); for (i = 0; i < blen; i++) b[blen-1-i] = str[i]-'0'; //cal int temp = 0; for (i = 0; i < (alen>blen?alen:blen); i++) { temp = a[i]+b[i]+temp; a[i] = temp % 10; temp = temp / 10; } if (0!=temp) a[i++] = temp; //output for (i--; i >=0; i--) cout << a[i]; return 0; }
原文地址:http://blog.csdn.net/weijj6608/article/details/44316001