Cod sursa(job #1792607)

Utilizator calin9819Costea Calin calin9819 Data 30 octombrie 2016 16:18:50
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f ("nunta.in");
ofstream g ("nunta.out");

short int s1[301], s2[301];

inline 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 main() {
    int N;
    f >> N;
    s1[0] = 1;
    s1[1] = 1;
    s2[0] = 1;
    s2[1] = 2;
    if (N == 1) g << 1;
    else if (N == 2) g << 2;
    else {
        for (int i = 3; i <= N; i++)
            if (i % 2 == 1)
                add (s1, s2);
            else add (s2, s1);
        if (N % 2 == 1)
            for (int i = s1[0]; i >= 1; i--)
                g << s1[i];
        else
            for (int i = s2[0]; i >= 1; i--)
                g << s2[i];


    }
    return 0;
}