Cod sursa(job #1276385)

Utilizator hasmasandragosHasmasan Dragos hasmasandragos Data 26 noiembrie 2014 11:56:59
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
using namespace std;

ifstream f("nunta.in");
ofstream g("nunta.out");

int a[102],b[102],n;

void adunare (int A[] , int B[])
{
    int t=0,i;
    for (i=1;i<=A[0] || i<=B[0] || t; i++ , t/=10)
    {
        t=t+A[i]+B[i];
        A[i]=t%10;
    }
    A[0]=i-1;
}

void atribuire (int A[], int B[])
{
    int i;
    for (i=1;i<=B[0];i++)
        A[i]=B[i];
    A[0]=B[0];
}

int main()
{
    a[0]=1; a[1]=1;
    b[0]=1; b[1]=2;
    f>>n;
    int i;
    if (n==1) g<<"1";
    else if (n==2) g<<"2";
    else
    {
        for (i=3;i<=n;i++)
        {
           if (i%2)
           adunare(a,b);
           else
           adunare(b,a);
        }
    }
    if (n%2==0)
    for (i=b[0];i>=1;i--)
        g<<b[i];
    else
    for (i=a[0];i>=1;i--)
        g<<a[i];
    f.close();
    g.close();
    return 0;
}