p1255 无法运行为什么?

P1255 数楼梯

wuzebang2009 @ 2024-11-22 21:12:20


#include<bits/stdc++.h>
using namespace std;
struct bigint{
    int len,f[5010];
    bigint(int x=0){
        memset(f,0,sizeof(f));
        for(len=1;x;len++){
            f[len]=x%10,x/=10;
        }
        len--;
    }
    int &operator[](int i){
        return f[i];
    }
    void flatten(int L){
        len=L;
        for(int i=1;i<=len;i++)
            f[i+1]+=f[i]/10,f[i]%=10;
        for(;!f[len];)
            len--;
    }
    void print(){
        for(int i=max(len,1);i>=1;i--)
            printf("%d",f[i]);
    }
};
bigint operator+(bigint a,bigint b){
    bigint c;
    int len=max(a.len,b.len);
    for(int i=1;i<=len;i++)
        c[i]+=a[i]+b[i];
    c.flatten(len+1);
    return c;
}
int main(){
    int n;
    scanf("%d",&n);
    bigint a[5010];
    a[1]=bigint(1);
    a[2]=bigint(2);
    for(int i=3;i<=n;i++){
        a[i]=a[i-2]+a[i-1];
    }
    a[n].print();
    return 0;
}
RE了为什么?

by hex4C45 @ 2024-11-22 21:18:52

你bigint的+重载写到结构体外面去了(大概吧)


|