VadimThink

М

Oct 7th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.76 KB | None | 0 0
  1. program project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. uses
  8.   System.SysUtils;
  9.  
  10. type
  11.     ToWorkArr = array of array of Integer;
  12.  
  13. function Check(Min,Max:Integer; Msg,Error, IntegerError:String):Integer;
  14. var
  15.     IsCorrect:Boolean;
  16.    Numb:Integer;
  17. begin
  18.     IsCorrect:= False;
  19.    Writeln(Msg);
  20.    repeat
  21.     try
  22.         Readln(Numb);
  23.         if((Numb > Min) and (Numb < Max)) and not Odd(Numb) then
  24.             IsCorrect:= True
  25.         else
  26.             Writeln(Error);
  27.       except
  28.         Writeln(IntegerError);
  29.       end;
  30.    until (IsCorrect);
  31. Check:=Numb;
  32. end;
  33.  
  34.  
  35. procedure FillArrKeyboard(var MyArr: ToWorkArr; LengthOfArr: Integer);
  36.  
  37. const
  38.    MinInt = - MaxInt - 1;
  39.  
  40. var
  41.    i, j: Integer;
  42.    CorrectFilling: Boolean;
  43.  
  44. begin
  45.    Writeln('Please, enter a numerical value with a range from ', MinInt, ' to ', MaxInt, '):');
  46.    for i := 0 to LengthOfArr do
  47.       for j := 0 to LengthOfArr do
  48.       begin
  49.  
  50.          repeat
  51.             CorrectFilling := False;
  52.             Write('A[', i, ', ', j, '] = ');
  53.             try
  54.                Readln(MyArr[i, j]);
  55.                CorrectFilling := True;
  56.             except
  57.                Writeln('Error! Please, enter a numerical value with a range from ', MinInt,
  58.                ' to ', MaxInt, '.');
  59.             end;
  60.          until (CorrectFilling);
  61.       end;
  62.    for i:=0 to LengthOfArr do
  63.    begin
  64.     for j:=0 to LengthOfArr do
  65.         Write('  ', MyArr[i,j] : 3);
  66.       Writeln;
  67.    end;
  68. end;
  69.  
  70. procedure Swap(var MyFirstArr: ToWorkArr; MySecondArr: ToWorkArr; LengthOfArr: Integer);
  71.  
  72. var
  73.    i, a, j, HalfOfLength, NextLine: Integer;
  74.  
  75. begin
  76.    HalfOfLength:= LengthOfArr div 2;
  77.    NextLine:= LengthOfArr div 2 + 1;
  78.    for i := 0 to HalfOfLength do
  79.     for j := 0 to LengthOfArr do
  80.             MySecondArr[((NextLine) + i),j] := MyFirstArr[i,j];
  81.    a := 0;
  82.    for i := (NextLine) to LengthOfArr do
  83.    begin
  84.     for j := LengthOfArr downto 0 do
  85.             MySecondArr[a, LengthOfArr - j] := MyFirstArr[i, j];
  86.       inc(a);
  87.    end;
  88. end;
  89.  procedure GetOutConclusion(MyArr: ToWorkArr; LengthOfArr: Integer);
  90.  var
  91.    i,j:Integer;
  92.  begin
  93.    Writeln('Result of matrix swap: ');
  94.    for i := 0 to LengthOfArr do
  95.    begin
  96.     for j := 0 to LengthOfArr do
  97.         Write('  ', MyArr[i,j] : 3);
  98.       Writeln;
  99.    end;
  100.  end;
  101.  
  102. procedure Main();
  103. var
  104.     ArrA, ArrB : ToWorkArr;
  105.    n, i, j, a : Integer;
  106.  
  107. begin
  108.    Writeln('Theme: There are a real square matrix of order 2n. It`s necessary to obtain a new matrix, where the sub-matrices are interchanged');
  109.    n := Check(1, 7, 'Enter the number of rows and columns of the square matrix', 'The number must be bigger than 2 but less then 6, the number must be even','The number must be an integer!');
  110.    SetLength(ArrA, n, n);
  111.    SetLength(ArrB,n, n);
  112.    n := n - 1;
  113.    FillArrKeyboard(ArrA,n);
  114.    Swap(ArrA,ArrB,n);
  115.    GetOutConclusion(ArrB,n);
  116.    Readln;
  117. end;
  118.  
  119. begin
  120.    Main();
  121. end.
Add Comment
Please, Sign In to add comment