Cod sursa(job #2497422)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 22 noiembrie 2019 17:13:11
Problema Grozavesti Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>
#include <vector>

#define NMAX 305
using namespace std;

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

struct chestie
{
    char ch;
    int x1, x2;
};

int mat[NMAX][NMAX], n;
vector<chestie> rez;

void swapC(int c1, int c2)
{
    for(int i = 1; i <= n; ++i)
        swap(mat[i][c1], mat[i][c2]);
}

void swapL(int l1, int l2)
{
    for(int j = 1; j <= n; ++j)
        swap(mat[l1][j], mat[l2][j]);
}

int main()
{
    fin >> n;

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            fin >> mat[i][j];

    for(int i = 2; i <= n; ++i)
    {
        int ci = i;
        while(mat[i][i] < mat[ci - 1][ci - 1])
            --ci;
        if(i != ci)
        {
            swapC(i, ci);
            swapL(i, ci);
            rez.push_back({'C', i, ci});
            rez.push_back({'L', i, ci});
            i -= 2;
        }
    }

    fout << rez.size() << '\n';
    for(int i = 0; i < rez.size(); ++i)
        fout << rez[i].ch << ' ' << rez[i].x1 << ' ' << rez[i].x2 << '\n';
    return 0;
}