Cod sursa(job #1998155)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 6 iulie 2017 19:20:56
Problema Tije Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
#include <string>

using namespace std;

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

const int nmax = 100;
const int buff = (1 << 20);

int v[ 3 ];
string s, nr[nmax + 5];

void baga (int x) {
    int cif = 0;
    int cp = x;
    while (x > 0) {
        v[ cif++ ] = x % 10;
        x /= 10;
    }

    for (int i = cif - 1; i >= 0; -- i) nr[ cp ] += '0' + v[ i ];
}

void muta (int x, int y) {
    s += nr[ x ];
    s += " ";
    s += nr[ y ];
    s += "\n";

    if (s.size() >= buff) {
        fout << s;
        s.clear();
    }
}

int main() {
    int n;

    fin >> n;

    for (int i = 1; i <= n + 1; ++ i) {
        baga( i );
    }

    for (int i = 1; i <= n - 1; ++ i) { /// cine da
        for (int j = 1; j <= n; ++ j) {
            int unde = j - 1;
            if (unde == 0) unde = n + 1;

            for (int k = 1; k <= n - i; ++ k) muta(j, unde);
        }

        for (int j = 1; j <= n - i; ++ j) muta(n + 1, n);
    }

    fout << s;

    fin.close(); fout.close();
    return 0;
}