Bài tập 6.22 sách bài tập tin học lớp 11 trang 66

· Thuật toán
Tác giả
const nmax=30;
      fi='HV.inp';
      fo='HV.out';
type mang=array[1..nmax,1..nmax] of integer;
var A: mang; n,i:integer;f:text;
    b:array[1..nmax,1..nmax] of boolean;
     procedure InputFile;
     var i,j:integer;
     begin
       assign(f,fi);
       reset(f);
          readln(f,n);
          for i:=1 to n do
           begin
             for j:=1 to n do
             read(f,A[i,j]);
             readln(f);
            end;
       close(f);
     end;

     procedure swap(var x,y:integer);
     var tg:integer;
     begin
        tg:=x;
        x:=y;
        y:=tg;
     end;

     procedure process;
     var i,j:integer;
     begin
     fillchar(b,sizeof(b),true);
      for i:=1 to n do
        for j:=1 to n do
        begin
         if b[i,j]=true then
          swap(A[i,j],A[j,i]);
          b[j,i]:=false;
          end;
     end;

     procedure OutputFile;
     var i,j:integer;
     begin
         assign(f,fo);
         rewrite(f);
         writeln(f,n);
           for i:=1 to n do
             begin
              for j:=1 to n do
                write(f,a[i,j]:3);
                writeln(f);
             end;
         close(f);
     end;
begin
  InputFile;
  process;
  OutputFile;
end.



Bình luận về bài viết này