Cod sursa(job #2875663)

Utilizator indianu_talpa_iuteTisca Catalin indianu_talpa_iute Data 22 martie 2022 09:39:04
Problema Nunta Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("nunta.in");
ofstream fout("nunta.out");

typedef vector<char> nr;
void add(nr &a, nr &b) {
    char t = 0;
    while (a.size() < b.size())
        a.push_back(0);
    for (int i = 0; i < b.size(); i++) {
        t += a[i] + b[i];
        a[i] = t % 10;
        t /= 10;
    }
    if (t)
        a.push_back(t);
}

int main() {
    int n;
    fin >> n;
    nr a, b;
    a.push_back(0);
    b.push_back(1);
    for (int i = 0; i < n; i++) {
        nr aux = b;
        add(b, a);
        a = aux;
    }

    for (int i = b.size() - 1; i >= 0; i--)
        fout << (int)b[i];
    return 0;
}