poj 3982 序列

#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");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值