HDU 1865(高精斐波那契)

高精斐波那契

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<functional>
#include<algorithm>
using namespace std;
#define MAXN (200+10)
#define F (1000)
struct bign
{
    int len;
    int a[1000];
    bign operator+(const bign& b)
    {
        bign c;
        memset(c.a,0,sizeof(c.a));
        c.len=max(len,b.len)+1;
        for (int i=1;i<=c.len;i++)
        {
            c.a[i]+=a[i]+b.a[i];
            c.a[i+1]+=c.a[i]/F;
            c.a[i]=c.a[i]%F;
        }
        if (c.a[c.len]==0&&c.len>1) c.len--;
        return c;               
    }
    bign operator= (int num)
    {
        memset(a,0,sizeof(a));
        a[1]=num;
        len=1;
        return *this;       
    }

};

bign f[MAXN];
int n;
int main()
{
    cin>>n;
    f[1]=1;f[2]=2;

    for (int i=3;i<=200;i++)
        f[i]=f[i-1]+f[i-2];

    for (int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        int j=s.length();
        cout<<f[j].a[f[j].len];
        for (int k=f[j].len-1;k>=1;k--)
        {
            if (f[j].a[k]<100) cout<<"0";
            if (f[j].a[k]<10) cout<<"0";
            printf("%d",f[j].a[k]);
        }
        cout<<"\n";

    }
//  for (int i=1;i<=200;i++) cout<<f[i].len;

    /*
    for (int j=1;j<=200;j++)
    {
        cout<<f[j].a[f[j].len];
        for (int k=f[j].len-1;k>=1;k--)
        {
            if (f[j].a[k]<100) cout<<"0";
            if (f[j].a[k]<10) cout<<"0";
            printf("%d",f[j].a[k]);
        }
        cout<<"\n";

    }*/
    return 0;
}