Cod sursa(job #2957715)

Utilizator AndreibatmanAndrei Croitoriu Andreibatman Data 23 decembrie 2022 13:07:38
Problema Grozavesti Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("grozavesti.in");
ofstream fout("grozavesti.out");
struct ceva
{
    char type;
    int f,s;
}ans[610];
int n,v[310],i,j,nr,x,maxi,poz;
int main()
{
    fin>>n;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
        {
            fin>>x;
            if(i==j)
                v[i]=x;
        }
    while(n)
    {
        maxi=poz=0;
        for(i=1;i<=n;i++)
            if(v[i]>maxi)
                maxi=v[i],poz=i;
        if(v[n]!=maxi)
        {
            ans[++nr].type='C';
            ans[nr].f=i;
            ans[nr].s=poz;

            ans[++nr].type='L';
            ans[nr].f=i;
            ans[nr].s=poz;

            swap(v[poz],v[n]);
        }
        n--;
    }
    fout<<nr<<'\n';
    for(i=1;i<=nr;i++)
        fout<<ans[i].type<<" "<<ans[i].f<<" "<<ans[i].s<<'\n';
    return 0;
}