Cod sursa(job #820818)

Utilizator andreea29Iorga Andreea andreea29 Data 21 noiembrie 2012 11:03:45
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.49 kb
#include<fstream>

#define Nmax 100000

using namespace std;

int n, v2[Nmax], v1[Nmax], aux[Nmax], t;

int main()
{
    ifstream f("nunta.in");
    ofstream h("nunta.out");
    f >> n;
    f.close();

    if (n == 1)
        h << "1\n";
    else
        if (n == 2)
            h << "2\n";
        else
        {
            v1[0] = 1;
            v1[1] = 1;
            v2[0] = 1;
            v2[1] = 2;
            n = n - 2;
            for (int i = 1; i <= n; ++i)
            {
                for (int j = 0; j <= v2[0]; ++j)
                    aux[j] = v2[j];
                t = 0;
                if (v1[0] > v2[0])
                {
                    for (int j = v2[0] + 1; j <= v1[0]; ++j)
                        v2[j] = 0;
                    v2[0] = v1[0];
                }
                else
                    for (int j = v1[0] + 1; j <= v2[0]; ++j)
                        v1[j] = 0;
                for (int j = 1; j <= v2[0]; ++j)
                {
                    v2[j] += v1[j] + t;
                    t= v2[j] / 10;
                    v2[j] %= 10;
                }
                if (t)
                {
                    ++v2[0];
                    v2[v2[0]] = t;
                }
                for (int j = 0; j <= v2[0]; ++j)
                    v1[j] = aux[j];
            }
            for (int i = v2[0]; i >= 1; --i)
                h << v2[i];
            h << '\n';
        }

    h.close();
    return 0;
}