Cod sursa(job #1401780)

Utilizator axelteoTeodor Dutu axelteo Data 26 martie 2015 09:35:35
Problema Nunta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <cstdio>
using namespace std;
short int a[250],b[250],c[250];
int main()
{
    FILE *in,*out;
    in=fopen("nunta.in","r");
    out=fopen("nunta.out","w");
    short int i,n,t,j;
    fscanf(in,"%hd",&n);
    a[0]=1;b[0]=1;c[0]=1;a[1]=1;b[1]=2;c[1]=3;
    for(i=3;i<=n;++i)
    {
        c[0]=b[0];
        t=0;
        for(j=1;j<=b[0];++j)
        {
            c[j]=(a[j]+b[j]+t)%10;
            t=(a[j]+b[j]+t)/10;
            a[j]=b[j];
        }
        if(t)
        {
            ++c[0];
            c[c[0]]=1;
        }
        for(j=1;j<=c[0];++j)
        {
            b[j]=c[j];
            c[j]=0;
        }
        a[0]=b[0];b[0]=c[0];
    }
    if(n<4)fprintf(out,"%hd",n);
    else for(i=b[0];i;--i)fprintf(out,"%hd",b[i]);
    fprintf(out,"\n");
    fclose(in);fclose(out);
    return 0;
}