建议平时写高精度的时候直接封装成一个函数,便于调用。举例:
```
struct NUM{
int c[210];
int& operator [](const int i){ return c[i]; }
NUM(){ memset(c,0,sizeof c); c[0] = 1; }
void init(){ c[0] = c[1] = 1; }
NUM friend operator +(NUM x,NUM y){
NUM res;
res[0] = max(x[0],y[0]);
for(int i = 1;i<=res[0]+1;++i){
res[i] += x[i] + y[i];
res[i+1] += res[i] / 10;
res[i] %= 10;
}
for(int i = 200;i;--i)
if(res[i]){ res[0] = i; break; }
return res;
}
void output(){
for(int i = c[0];i;--i)printf("%d",c[i]);
}
}f[N];
```
tips:我这里自己写的,c[0]的含义是数的位数len。
by fight_for_humanity @ 2024-04-06 08:24:28
哦,说错了是封装为结构体
by fight_for_humanity @ 2024-04-06 08:26:26
@[lucy2012](/user/1252442)
主函数
```
scanf("%d",&n);
f[1].init(),f[0].init();
for(int i = 2;i<=n;++i)f[i] = f[i-1] + f[i-2];
f[n].output();
```
还有这道题结构体里c要开大点
by fight_for_humanity @ 2024-04-06 08:36:48
@[fight_for_humanity](/user/1051647) 个人觉得函数更好
by liuruiqing @ 2024-04-06 08:40:50