poj 3982 序列

來源:互聯網
上載者:User
#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");}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.