Cod sursa(job #754303)

Utilizator SteveStefan Eniceicu Steve Data 1 iunie 2012 15:49:45
Problema Nunta Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <cstdio>

using namespace std;

int N;
int v[2][200];

int main ()
{
    int o;
    freopen ("nunta.in", "r", stdin);
    freopen ("nunta.out", "w", stdout);
    scanf ("%d", &N);
    if (N <= 3)
    {
        printf ("%d", N);
        return 0;
    }
    v[0][0] = 1;
    v[0][1] = 1;
    v[1][0] = 1;
    v[1][1] = 2;
    o = 0;
    int j, t;
    for (int y = 3; y <= N; y++)
    {
        t = 0;
        for (j = 1; j <= v[o][0] || t; j++)
        {
            v[o][j] += t + v[!o][j];
            t = v[o][j] / 10;
            v[o][j] %= 10;
        }
        v[o][0] = j - 1;
        o = !o;
    }
    o = !o;
    for (int i = v[o][0]; i >= 1; i--)
    {
        printf ("%d", v[o][i]);
    }
    return 0;
}