View Code of Problem 23

#include <iostream>
#include "vector"

using namespace std;

/**
 * kkmd66 四刷
 * @return
 */

int main() {

    //预先创建好答案序列
    vector<long long> answer(90);
    for (int i = 0; i < answer.size(); ++i) {
        if (i == 0)
            answer[i] = 1;
        else if (i == 1)
            answer[i] = 2;
        else {
            answer[i] = answer[i - 1] + answer[i - 2];
        }
    }

    //输入
    int n;
    while (cin >> n && n != 0) {
        cout << answer[n - 1] << endl;
    }

    return 0;
}

Double click to view unformatted code.


Back to problem 23