Advertisement
bogdanpashtet

from exam

Jan 15th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.39 KB | None | 0 0
  1. program fakhri;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   windows,
  7.   SysUtils;
  8.  
  9. const n_max = 10;
  10.  
  11. type matrix = array[1..n_max,1..n_max] of integer;
  12.  
  13. procedure rus;
  14.   begin
  15.     setconsolecp(1251);
  16.     setconsoleoutputcp(1251);
  17.   end;
  18.  
  19. procedure input_n_m(out n,m:shortint; out fl:boolean);
  20.   begin
  21.     fl:=true;
  22.     readln(n);
  23.     if (n>n_max) or (n<1) then
  24.       fl:=false;
  25.     readln(m);
  26.     if ((m>n_max) or (m<1)) and (fl=true) then
  27.       fl:=false;
  28.   end;
  29.  
  30. procedure input_matrix(const n,m:shortint; out a:matrix);
  31.   var
  32.     i,j:shortint;
  33.   begin
  34.     i:=0;
  35.     while (i<n) do
  36.       begin
  37.         inc(i);
  38.         j:=0;
  39.         while (j<m) do
  40.           begin
  41.             inc(j);
  42.             read(a[i,j]);
  43.           end;
  44.         readln;
  45.       end;
  46.   end;
  47.  
  48. procedure analysis(const a,b:matrix; const n,m:shortint; out stolb:shortint; out fl1:boolean);
  49.   var
  50.     i,j:shortint;
  51.   begin
  52.     i:=0;
  53.     fl1:=true;
  54.     stolb:=-1;
  55.     while (i<n) and (fl1=true) do
  56.       begin
  57.         inc(i);
  58.         j:=0;
  59.         while (j<m) and (fl1=true) do
  60.           begin
  61.             inc(j);
  62.             if (a[i,j] <> b[i,j]) then
  63.               begin
  64.                 stolb:=j;
  65.                 fl1:=false;
  66.               end
  67.           end;
  68.       end;
  69.   end;
  70.  
  71. procedure zamena(const a:matrix; var b:matrix; const stolb:shortint; const n,m:shortint);
  72.   var
  73.     i:shortint;
  74.     gg:shortint;
  75.   begin
  76.     i:=0;
  77.     while (i<n) do
  78.       begin
  79.         inc(i);
  80.         gg:=b[i,m];
  81.         b[i,m]:=b[i,stolb];
  82.         b[i,stolb]:=gg;
  83.       end;
  84.   end;
  85.  
  86. procedure output(const n,m:shortint; const a:matrix);
  87.   var
  88.     i,j:shortint;
  89.   begin
  90.     for i:=1 to n do
  91.       begin
  92.         for j:=1 to m do
  93.           begin
  94.             write(a[i,j]:5,' ');
  95.           end;
  96.         writeln;
  97.       end;
  98.     writeln;
  99.   end;
  100.  
  101. var
  102.   a,b:matrix;
  103.   n,m,stolb:shortint;
  104.   fl,fl1:boolean;
  105.  
  106.  
  107. begin
  108.   rus;
  109.   input_n_m(n,m,fl);
  110.   if fl = false then
  111.       begin
  112.         writeln('Некорректное n или m');
  113.       end
  114.   else
  115.     begin
  116.       input_matrix(n,m,a);
  117.       input_matrix(n,m,b);
  118.       analysis(a,b,n,m,stolb,fl1);
  119.       output(n,m,a);
  120.       output(n,m,b);
  121.       if (fl1 = false) then
  122.         begin
  123.           writeln('done');
  124.           zamena(a,b,stolb,n,m);
  125.           output(n,m,b)
  126.         end
  127.       else
  128.         writeln('Равно.');
  129.     end;
  130.  
  131.   readln;
  132. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement