Cod sursa(job #2389220)

Utilizator qThunderStefan Durlanescu qThunder Data 26 martie 2019 21:30:22
Problema Grozavesti Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("grozavesti.in");
ofstream fout("grozavesti.out");
int n,st,dr,x,maxim,i1,k;
struct Metropolispt1
{
    int a,b;
    char c;
};
Metropolispt1 v1[604];
struct Metropolispt2
{
    int a,l,c;
};
Metropolispt2 v[304];
int main()
{
    fin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            fin>>x;
            if(i==j)
            {
                v[i].a=x;
                v[i].l=i;
                v[i].c=j;
            }
        }
    for(int i=n;i>1;i--)
    {
        maxim=0;
        i1=0;
        for(int j=1;j<=i;j++)
            if(maxim<v[j].a)
            {
                maxim=v[j].a;
                i1=j;
            }
        int i2=i;
        if(v[i2].a==v[i1].a)
            continue;
        v1[++k].c='C';
        v1[k].a=v[i1].c;
        v1[k].b=v[i2].c;
        v1[++k].c='L';
        v1[k].a=v[i1].l;
        v1[k].b=v[i2].l;
        swap(v[i1],v[i2]);
    }
    fout<<k<<"\n";
    for(int i=1;i<=k;i++)
    {
        fout<<v1[i].c<<" "<<v1[i].a<<" "<<v1[i].b<<"\n";
    }
    return 0;
}