Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 19th, 2012  |  syntax: Pascal  |  size: 2.02 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils,
  7.   Windows;
  8.  
  9. const m = 3; //Здесь размер матрицы, поменяй на что-нибудь свое
  10. type TMatrix = array[1..m,1..m] of integer;
  11. var
  12.     a:TMatrix;
  13.     i,j,p,q:integer;
  14. procedure InputData(var x:TMatrix);
  15. var i,j:integer;
  16. begin
  17.     for i:=1 to m do
  18.         for j:=1 to m do
  19.         begin
  20.             writeln('Введите элемент матрицы ',i,' ',j);
  21.             readln(x[i,j]);
  22.         end;
  23. end;
  24. function NullRow(const x:TMatrix; y:integer):boolean; //Состоит ли строка из нулей?
  25. var i:integer;
  26.     r:boolean;
  27. begin
  28.     r:=true;
  29.     for i:=1 to m do
  30.         if x[y,i]<>0 then r:=false;
  31.     NullRow:=r;
  32. end;
  33. function NullColumn(const x:TMatrix; y:integer):boolean; //Состоит ли столбец из нулей?
  34. var i:integer;
  35.     r:boolean;
  36. begin
  37.     r:=true;
  38.     for i:=1 to m do
  39.         if x[i,y]<>0 then r:=false;
  40.     NullColumn:=r;
  41. end;
  42. procedure RemoveRow(var x:TMatrix; y:integer); //Удаляем строку
  43. var i:integer;
  44. begin
  45.     if y<>m then
  46.         for i:=1 to m do
  47.             x[y,i]:=x[y+1,i];
  48. end;
  49. procedure RemoveColumn(var x:TMatrix; y:integer); //Удаляем столбец
  50. var i:integer;
  51. begin
  52.     if y<>m then
  53.         for i:=1 to m do
  54.             x[i,y]:=x[i,y+1];
  55. end;
  56. procedure PrintMatrix(const x:TMatrix; p:integer; q:integer);
  57. var i,j:integer;
  58. begin
  59.     for i:=1 to p do
  60.     begin
  61.         for j:=1 to q do write(x[i,j], ' ');
  62.         writeln;
  63.     end;
  64. end;
  65. begin
  66.     SetConsoleCp(1251); SetConsoleOutputCp(1251);
  67.     InputData(a);
  68.     p:=m; //Строк в конечной матрице
  69.     q:=m; //Столбцов
  70.     for i:=m downto 1 do
  71.     begin
  72.         if NullRow(a,i) then
  73.         begin
  74.             RemoveRow(a,i);
  75.             p:=p-1;
  76.         end;
  77.         if NullColumn(a,i) then
  78.         begin
  79.             RemoveColumn(a,i);
  80.             q:=q-1;
  81.         end;
  82.     end;
  83.     PrintMatrix(a, p, q);
  84.     readln;
  85. end.