Cod sursa(job #1702784)

Utilizator moise_alexandruMoise Alexandru moise_alexandru Data 15 mai 2016 15:56:19
Problema Grozavesti Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream in("grozavesti.in");
ofstream out("grozavesti.out");
const int maxn = 305;
int v[maxn];
int lin[maxn];
int col[maxn];
char T[maxn * 3];
int n, poz;
inline void citire()
{
    in.getline(T + 1, maxn);
    for(int i = 1; i <= n; i++)
    {
        in.getline(T + 1, maxn * 3);
        int sz = strlen(T + 1);
        int space = 1;
        int poz = 1;
        while(space < i)
            if(T[poz++] == ' ')
                space++;
        for(int j = poz; j <= sz && T[j] != ' '; j++)
            v[i] = v[i] * 10 + T[j] - '0';
    }
}

int main()
{
    in >> n;
    citire();
    int p = 0;
    for(int i = n; i > 1; i--)
    {
        int mx = v[1];
        poz = 1;
        for(int j = 2; j <= i; j++)
        {
            if(mx < v[j])
            {
                mx = v[j];
                poz = j;
            }
        }
        if(poz != i)
        {
            swap(v[poz], v[i]);
            p++;
            lin[p] = i;
            col[p] = poz;
        }
    }
    out << p * 2 << "\n";
    for(int i = 1; i <= p; i++)
    {
        out << "C " << lin[i] << " " << col[i] << "\n";
        out << "L " << lin[i] << " " << col[i] << "\n";
    }
    return 0;
}