Cod sursa(job #1445302)

Utilizator cernat.catallinFMI Cernat Catalin Stefan cernat.catallin Data 30 mai 2015 13:10:06
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include<fstream>
#include <iostream>
using namespace std;

const int lmax = 500005;

int main() {
    ifstream in("staropramen.in");
    ofstream out("staropramen.out");
    char buffer[lmax];
    int t;
    in >> t;
    for (int k = 0; k < t; ++k) {
        int n;
        in >> n;
        char c1, c2;
        for (int i = 1; i <= n; ++i) {
            in >> c1 >> c2;
            buffer[i] = (c1 - '0') * 10 + (c2 - '0');
        }
        int r = 0;
        for (int i = n; i > 0; --i) {
            int d1 = buffer[i] / 10;
            int d2 = buffer[i] % 10;

            buffer[i] = ((r += (d1 + d2)) % 10);
            r /= 10;
        }
        if (r)
            out << r;
        int cont = 0;
        for (int i = 1; i <= n; ++i) {
            out << static_cast<int> (buffer[i]);
            if (cont == 10) {
                cont = 0;
                out.flush();
            }
        }
        out << '\n';
    }
    return 0;
}