Cod sursa(job #143750)

Utilizator cristiprgPrigoana Cristian cristiprg Data 26 februarie 2008 20:29:57
Problema Nunta Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.42 kb
#include"fstream.h"
#define dim 500
//using namespace std;

int A[dim],B[dim],F[dim];
int n;

int main()
{
    ifstream fin("nunta.in");
    fin>>n;
    fin.close();
    
    A[0]=B[0]=F[0]=1;
    A[1]=B[1]=1;
        
    int i,j,t;
    for(i=3;i<=n+1;++i)
       {
           //f=a+b
        //   add(A[],B[]);
           t=0;
           for(j=1;j<=A[0] || j<=B[0] || t ;j++,t/=10)
                A[j]=(t+=A[j]+B[j])%10;
           A[0]=j-1;
        
        
        
           for(j=0;j<=A[0];++j)   
                F[j]=A[j];
           //a=b;
           for(j=0;j<=B[0];++j)
                A[j]=B[j];
           //b=f;
           for(j=0;j<=F[0];++j)
                B[j]=F[j];
            }
     
     
     ofstream fout("nunta.out");
     if(n==1)
       fout<<1;
     else
     
     for(i=1;i<=F[0];++i)
        fout<<F[i];
     fout.close();
     return 0;
     }