Cod sursa(job #2057878)

Utilizator SburlyAndrei Florin Sburly Data 4 noiembrie 2017 20:48:14
Problema Nunta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <cstdio>

using namespace std;

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

int n;
short int x[210], y[210];

int main()
{
    freopen("nunta.in","r",stdin);
    freopen("nunta.out","w",stdout);

    scanf("%d", &n);

    if(n == 1)
    {
        fputc('1', stdout);
        return 0;
    }
    if(n == 2)
    {
        fputc('2',stdout);
        return 0;
    }


    x[0] = 1;
    y[0] = 1;
    x[1] = 1;
    y[1] = 2;

    bool b = true;
    for(int i = 2; i < n; i++, b =!b)
        if(b)
            add(x,y);
        else
            add(y,x);

    if(b)
        for(int i = y[0]; i > 0; i--)
            fputc(y[i]+'0',stdout);
    else
        for(int i = x[0]; i > 0; i--)
            fputc(x[i]+'0',stdout);

    return 0;
}