Cod sursa(job #118160)

Utilizator ProtomanAndrei Purice Protoman Data 23 decembrie 2007 12:05:38
Problema Grozavesti Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.41 kb
type grozav=record
            x,ii:longint;
     end;

var f1,f2:text;
    i,j,n,nr,h,a:longint;
    sol:array[0..1000] of grozav;
    aux:grozav;
begin
        assign(f1,'grozavesti.in');
        reset(f1);
        assign(f2,'grozavesti.out');
        rewrite(f2);
        read(f1,n);
        for i:=1 to n do
        begin
                sol[i].ii:=i;
                for j:=1 to n do
                begin
                        read(f1,a);
                        if i=j then
                                sol[i].x:=a;
                end;
        end;
        for i:=1 to n-1 do
        begin
                h:=i;
                for j:=i+1 to n do
                begin
                        if sol[i].x>sol[j].x then
                        begin
                                aux:=sol[i];
                                sol[i]:=sol[j];
                                sol[j]:=aux;
                                h:=j;
                        end;
                end;
                sol[h].ii:=h;
                if sol[i].ii<>i then
                        inc(nr,2);
        end;
        writeln(f2,nr);
        for i:=1 to n do
                if sol[i].ii<>i then
                begin
                        writeln(f2,'L ',i,' ',sol[i].ii);
                        writeln(f2,'C ',i,' ',sol[i].ii);
                end;
        close(f1);
        close(f2);
end.