Cod sursa(job #754289)

Utilizator SteveStefan Eniceicu Steve Data 1 iunie 2012 15:13:01
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <cstring>

using namespace std;

int N, o;
int v[2][350];

void Citire ()
{
    ifstream fin ("nunta.in");
    fin >> N;
    fin.close ();
}

void Sum ()
{
    int j, 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;
}

void Business ()
{
    memset (v, 0, sizeof (v));
    v[0][0] = 1;
    v[0][1] = 1;
    v[1][0] = 1;
    v[1][1] = 2;
    o = 0;
    for (int y = 3; y <= N; y++, o = !o)
    {
        Sum ();
    }
    ofstream fout ("nunta.out");
    o = !o;
    for (int i = v[o][0]; i >= 1; i--)
    {
        fout << v[o][i];
    }
    fout.close ();
}

int main ()
{
    Citire ();
    if (N < 3)
    {
        ofstream fout ("nunta.out");
        fout << N;
        fout.close ();
        return 0;
    }
    Business ();
    return 0;
}