Cod sursa(job #2022563)

Utilizator LeVladzCiuperceanu Vlad LeVladz Data 16 septembrie 2017 18:54:24
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>

using namespace std;

ifstream fin("nunta.in");
ofstream fout("nunta.out");

short n,i;
short a[210],b[210];

void adun(short A[], short B[])
{
    short m = max(A[0], B[0]);
    short t = 0;
    short aux = 0;
    for (short i=1; i<=m; i++)
    {
        aux = B[i];
        B[i] += A[i]+t;
        t = B[i]/10;
        B[i] %= 10;
        A[i] = aux;
    }
    B[0] = m;
    if (t != 0)
        B[++B[0]] = t;
}

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

int main()
{
    fin >> n;
    if (n == 1)
    {
        fout << 1;
        return 0;
    }
    a[0] = b[0] = a[1] = b[1] = 1;
    for (i=1; i<=n-1; i++)
        adun(a, b);
    for (i=b[0]; i>=1; i--)
        fout << b[i];
    return 0;
}