#include <iostream>
#include <string>
#include <memory.h>
using namespace std;
string str[1000];
int n;
string solve(string str1, string str2, string str3)
{
int i, j, c, nn, len1, len2, len3, num1[100], num2[100], num3[100], tmp[100];
len1 = str1.length();
len2 = str2.length();
len3 = str3.length();
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
memset(num3, 0, sizeof(num3));
memset(tmp, 0, sizeof(tmp));
//cout << len1 << " " << len2 << " " << len3 << endl;
for (i = len1-1, j = 0; i >= 0; i--, j++){
num1[j] = str1[i] - 48;
}
//for (i = 0; i < j; i++)
// cout << num1[i] << endl;
for (i = len2-1, j = 0; i >= 0; i--, j++){
num2[j] = str2[i] - 48;
}
//for (i = 0; i < j; i++)
// cout << num2[i] << endl;
for (i = len3-1, j = 0; i >= 0; i--, j++){
num3[j] = str3[i] - 48;
}
//for (i = 0; i < j; i++)
// cout << num3[i] << endl;
c = 0;
for (i = 0; i < 100; i++){
tmp[i] = num1[i] + num2[i] + num3[i] + c;
if (tmp[i] >= 10){
c = tmp[i] / 10;
tmp[i] %= 10;
}
else c = 0;
}
//for (i = 0; i < 100; i++)
// cout << tmp[i];
//cout << endl;
for (nn = 100 - 1; nn >= 0; nn--){
if (tmp[nn] != 0)
break;
}
//cout << nn << endl;
str[n+1].clear();
for (i = nn; i >= 0; i--){
str[n+1].push_back(tmp[i]+48);
}
//cout << str[n+1] << endl;
//return str[n+1];
}
int main()
{
int i, len;
while (cin >> str[0] >> str[1] >> str[2]){
n = 2;
if (str[0] == "0" && str[1] == "0" && str[2] == "0")
cout << 0 << endl;
else{
while (n <= 99){
solve(str[n-2], str[n-1], str[n]);
n++;
}
len = str[99].length();
for (i = 0; i < len; i++)
cout << str[99][i];
cout << endl;
}
}
system("pause");
}
poj 3982 序列
最新推荐文章于 2022-02-25 21:57:21 发布