Cod sursa(job #1997083)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 3 iulie 2017 12:41:48
Problema Tije Scor 30
Compilator cpp Status done
Runda Simulare 18b Marime 1.43 kb
#include <fstream>
#include <string>

using namespace std;

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

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

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 = 0; i < cif; ++ 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; ++ i) { /// cine da
        for (int j = i + 1; j <= n; ++ j) { /// unde da

            /// eliberez toata coloana j
            for (int k = 1; k <= n; ++ k) muta(j, n + 1);
            /// pun i pe j
            muta(i, j);
            /// mut toata coloana inapoi mai putin un j
            for (int k = 1; k < n; ++ k) muta(n + 1, j);
            /// mut totata coloana i pe n + 1
            for (int k = 1; k < n; ++ k) muta(i, n + 1);
            /// ca sa am loc sa pun un j pe i
            muta(j, i);
            /// mut restul coloanei i inapoi
            for (int k = 1; k < n; ++ k) muta(n + 1, i);
            /// pun ultimul j inapoi pe coloana j
            muta(n + 1, j);
        }
    }

    fout << s;

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