Cod sursa(job #2312114)

Utilizator razviii237Uzum Razvan razviii237 Data 4 ianuarie 2019 12:02:50
Problema Nunta Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <iostream>
#include <fstream>

using namespace std;

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

typedef long long lint;
typedef unsigned long long ulint;
typedef int huge[105];

int n, i;
huge a, b, c;

void cpy(huge to, huge from) {
    for(int i = from[0]; i >= 0; i --) {
        to[i] = from[i];
    }
}

void add(huge s, huge x, huge y) {
    int i = 0, sum = 0;
    bool ok = true;
    for(i = 1; ok == true; i ++) {
        s[i] = (i <= x[0] ? x[i] : 0) + (i <= y[0] ? y[i] : 0) + sum;
        sum = s[i] / 10;
        s[i] %= 10;
        if(i >= x[0] && i >= y[0] && sum == 0) {
            s[0] = i;
            ok = false;
        }
    }
}

void print(huge x) {
    for(int i = x[0]; i >= 1; i --) {
        g << x[i];
    }
}

int main()
{
    f >> n;

    if(n == 1) {
        g << 1; return 0;
    }

    a[0] = 1; a[1] = 1;
    b[0] = 1; b[1] = 1;
    for(i = 2; i <= n; i ++)  {
        add(c, a, b);
        cpy(a, b);
        cpy(b, c);
    }

    print(c);
    //g << c << '\n';

    f.close();
    g.close();
    return 0;
}