Cod sursa(job #1916347)

Utilizator DanielRusuDaniel Rusu DanielRusu Data 9 martie 2017 09:09:30
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.54 kb
#include <iostream>
#include <cstdio>

using namespace std;

#define DIM 230

char f2[DIM], f3[DIM];
int x;
char N;

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

    cin >> x;
    N = x;

    if(N < 4) {
        cout << (int)N << '\n';
        return 0;
    }

    f2[0] = 1, f2[1] = 2;
    f3[0] = 1, f3[1] = 3;
    bool x = true;

    for(char i = 4; i <= N; ++i) {
        if(x == true) {
            char j = 1;
            char cat = 0;

            while(j <= f2[0] || j <= f3[0] || cat) {
                f2[j] = (int)f2[j] + (int)f3[j] + (int)cat;
                cat = char((int)f2[j] / (int)10);
                f2[j] %= (int)10;

                f2[0] = (char)max((int)f2[0], (int)j);
                j = (char)(j + 1);
            }
            x = false;
        }
        else {
            char j = 1;
            char cat = 0;

            while(j <= f2[0] || j <= f3[0] || cat) {
                f3[j] = (int)f2[j] + (int)f3[j] + (int)cat;
                cat = char((int)f3[j] / (int)10);
                f3[j] %= (int)10;

                f3[0] = max((int)f3[0], (int)j);
                j++;
            }
            x = true;
        }
    }

    if(x == true) {
        for(char i = (int)f3[0]; i > 0; --i) {
            cout <<(int)f3[(int)i];
        }

        cout << '\n';
    }
    else {
        for(char i = (int)f2[0]; i > 0; --i) {
            cout << (int)f2[(int)i];
        }

        cout << '\n';
    }

    return 0;
}