Cod sursa(job #137016)

Utilizator eugen.nodeaEugen Nodea eugen.nodea Data 16 februarie 2008 18:53:56
Problema Grozavesti Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.16 kb
Const fin ='grozaves.in';
      fout='grozaves.out';
      nmax=300;
Type cel=Record
               L1,C1,L2,C2:integer;
         End;
Var
   f:text;
   A:Array[1..nmax,1..nmax] of LongInt;
   p,i,j,n,k:integer;
   x,min:longint;
   B:array[1..nmax] of cel;

Begin
     assign(f,fin); reset(f);
     readln(f,n);
     For i:=1 to n do
         For j:=1 to n Do
             Read(f,a[i,j]);
     close(f);
     k:=0;
     for i:=1 to n-1 do
     begin
          p:=i;
          for j:=i+1 to n do
            if a[j,j]<a[p,p] then  p:=j;
          if p<>i then begin
                             x:=a[i,i];
                             a[i,i]:=a[p,p];
                             a[p,p]:=x;
                             k:=k+1;
                             B[k].L1:=i;
                             B[k].L2:=p;
                             B[k].C1:=i;
                             B[k].C2:=p;
                             end;
     end;
     assign(f,fout);rewrite(f);
     Writeln(f,2*k);
     For i:=1 to k do
     begin
         Writeln(f,'C ',B[i].C1,' ',B[i].C2);
         Writeln(f,'L ',B[i].L1,' ',B[i].L2);
     end;
     close(f);
End.