Cod sursa(job #1743387)

Utilizator fanache99Constantin-Buliga Stefan fanache99 Data 18 august 2016 03:11:24
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;

ifstream cin("nunta.in");
ofstream cout("nunta.out");

const int MAXD = 210;

char a[MAXD], b[MAXD];

int main() {
    short n, nra, nrb, j, k, i, temp, digit;
    cin >> n;
    if (n == 1) {
        cout << "1\n";
        return 0;
    }
    if (n == 2) {
        cout << "2\n";
        return 0;
    }
    if (n == 3) {
        cout << "3\n";
        return 0;
    }
    a[0] = 2;
    b[0] = 3;
    nra = 0, nrb = 0;
    for (j = 4; j <= n; j++) {
        k = 0;
        for (i = 0; i <= nra || i <= nrb || k != 0; i++) {
            temp = a[i];
            a[i] = b[i];
            digit = temp + k + b[i];
            b[i] = (temp + k + b[i]) % 10;
            k = digit / 10;
        }
        nra = nrb;
        nrb = i - 1;
    }
    for (i = nrb; i >= 0; i--)
        cout << (short int) b[i];
    return 0;
}