#include<iostream>
#include<vector>
using namespace std;
const int maxn = 1024;
const vector<int>* fib_seq(int size) {
static vector<int> elems;
if (size <= 0 || size > maxn)
cout << "wrong size!" << endl;
for (int ix = elems.size(); ix < size; ++ix) {
if (ix <= 1)
elems.push_back(1);
else
elems.push_back(elems[ix - 1] + elems[ix - 2]);
}
return &elems;
}
int main() {
const vector<int>* p = fib_seq(20);
for(int i = 0; i < 10; ++i)
cout << (*p)[i]<<"\t";
p = fib_seq(40);
cout <<"\n"<< (*p)[35] << endl;
}
【Essential C++代码笔记】static
最新推荐文章于 2024-02-24 18:14:58 发布