Yaoshui_lv @ 2024-10-02 20:15:48
如下代码
样例 10
输出 9
答案 89
请各位巨佬们看一看哪里错了QwQ
#include <iostream>
#include <vector>
using namespace std;
vector < vector <int> > ans(5010);
vector<int> add(vector <int> a, vector <int> b) {
vector < int > c;
vector < int > ans;
for (int i = 0; i < max(a.size(), b.size()); i++) {
ans.push_back(a[i]+b[i]);
ans[i+1] = ans[i]/10;
ans[i] = ans[i] % 10;
}
for (int i = ans.size()-1; i >= 0; i--) {
c.push_back(ans[i]);
}
return c;
}
signed main() {
int n;
cin >> n;
ans[1].push_back(1);
ans[2].push_back(2);
for (int i = 3; i <= n; i++) {
ans[i] = add(ans[i-1], ans[i-2]);
}
bool flag = true;
for (int i = 0; i < ans[n].size(); i++) {
if (flag) {
if (ans[n][i] == 0) continue;
else flag = 0;
}
cout << ans[n][i];
}
return 0;
}
by LLVM_lldb_14_0_0 @ 2024-10-03 09:18:59
@Yaoshui_lv 我建议你用我的高精度模板对比下?
by dongzirui0817 @ 2024-10-08 13:21:16
@Yaoshui_lv
代码越界处太多了,建议用数组(话说 vector 这么好用的吗)