Cod sursa(job #2228387)

Utilizator tanasaradutanasaradu tanasaradu Data 3 august 2018 15:22:32
Problema Grozavesti Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <bits/stdc++.h>

using namespace std;

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

const short NMAX = 305;

int a[NMAX][NMAX] , b[NMAX] , n;

struct T
{
    char ch;
    int lin , col;
};
T sol[2 * NMAX];

int main()
{
    int x , dim = 0;
    fin >> n;
    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= n ; j++)
        {
            fin >> x;
            a[i][j] = x;
            if(i == j)
                b[i] = x;
        }
    sort(b + 1 , b + n + 1);
    for(int i = 1 ; i <= n ; i++)
    {
        if(b[i] == a[i][i])
            continue;
        for(int j = i + 1 ; j <= n ; j++)
            if(a[j][j] == b[i])
                 sol[++dim] = {'L' , i , j} , sol[++dim] = {'C' , i , j} , swap(a[i][i] , a[j][j]);
    }
    fout << dim << "\n";
    for(int i = 1 ; i <= dim ; i++)
        fout << sol[i] . ch << " " << sol[i] . lin << " " << sol[i] . col << "\n";
    fin.close();
    fout.close();
     return 0;
}