Advertisement
altervisi0n

Untitled

Jun 30th, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 17.33 KB | None | 0 0
  1. unit MainUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  7.   System.Classes, Vcl.Graphics,
  8.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, Vcl.ExtCtrls,
  9.   Vcl.Menus;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     Description1: TLabel;
  14.     InputM: TEdit;
  15.     InputN: TEdit;
  16.     Create: TButton;
  17.     InfoM: TLabel;
  18.     InfoN: TLabel;
  19.     Matrix: TStringGrid;
  20.     Description2: TLabel;
  21.     Help: TLabel;
  22.     ElementA: TButton;
  23.     ElementB: TButton;
  24.     MaxPath: TButton;
  25.     PathLabel: TLabel;
  26.     Timer1: TTimer;
  27.     MainMenu1: TMainMenu;
  28.     PopupMenu1: TPopupMenu;
  29.     N1: TMenuItem;
  30.     N2: TMenuItem;
  31.     N3: TMenuItem;
  32.     N4: TMenuItem;
  33.     N5: TMenuItem;
  34.     OpenDialog1: TOpenDialog;
  35.     SaveDialog1: TSaveDialog;
  36.     procedure InputMKeyPress(Sender: TObject; var Key: Char);
  37.     procedure InputNKeyPress(Sender: TObject; var Key: Char);
  38.     procedure InputMChange(Sender: TObject);
  39.     procedure InputNChange(Sender: TObject);
  40.     procedure CreateClick(Sender: TObject);
  41.     procedure MatrixKeyPress(Sender: TObject; var Key: Char);
  42.     procedure MatrixSetEditText(Sender: TObject; ACol, ARow: Integer;
  43.       const Value: string);
  44.     procedure ElementAClick(Sender: TObject);
  45.     procedure MatrixSelectCell(Sender: TObject; ACol, ARow: Integer;
  46.       var CanSelect: Boolean);
  47.     procedure ElementBClick(Sender: TObject);
  48.     procedure MaxPathClick(Sender: TObject);
  49.     procedure Timer1Timer(Sender: TObject);
  50.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  51.     procedure N5Click(Sender: TObject);
  52.     procedure N4Click(Sender: TObject);
  53.     procedure N2Click(Sender: TObject);
  54.   private
  55.     { Private declarations }
  56.   public
  57.     { Public declarations }
  58.   end;
  59.  
  60. type
  61.   Elements = record
  62.     Elem: Integer;
  63.     I: Byte;
  64.   end;
  65.  
  66.   TMatrix = array of array of Elements;
  67.   TBoolMatrix = Array of Array of Boolean;
  68.  
  69.   TPoint = Record
  70.     X, Y: Integer;
  71.     Color: TColor;
  72.   End;
  73.  
  74.   TPath = Array of TPoint;
  75.   TArray = Array Of Integer;
  76.   TStr = Array of String[5];
  77.  
  78. var
  79.   Form1: TForm1;
  80.   Arr: TMatrix;
  81.   IsFileOpen, SelectA, SelectB: Boolean;
  82.   I1, J1, I2, J2, FinishRowPoint, FinishColPoint, StartRowPoint,
  83.     StartColPoint: Integer;
  84.   FilePath: String;
  85.   Path: TPath;
  86.   M, N, I: Integer;
  87.   CellColor: TColor;
  88.  
  89. implementation
  90.  
  91. {$R *.dfm}
  92.  
  93. procedure TForm1.CreateClick(Sender: TObject);
  94. var
  95.   IsCorrect: Boolean;
  96. begin
  97.   IsCorrect := True;
  98.   try
  99.     M := StrToInt(InputM.Text);
  100.   except
  101.     IsCorrect := False;
  102.     MessageBox(Form1.Handle,
  103.       Pchar('Проверьте поле для ввода кол-ва строк матрицы.'), 'Ошибка',
  104.       MB_ICONSTOP);
  105.   end;
  106.   If IsCorrect then
  107.   begin
  108.     try
  109.       N := StrToInt(InputN.Text);
  110.     except
  111.       IsCorrect := False;
  112.       MessageBox(Form1.Handle,
  113.         Pchar('Проверьте поле для ввода кол-ва столбцов матрицы.'), 'Ошибка',
  114.         MB_ICONSTOP);
  115.     end;
  116.   end;
  117.   If IsCorrect then
  118.   begin
  119.     SetLength(Arr, M, N);
  120.     Matrix.ColCount := N;
  121.     Matrix.RowCount := M;
  122.     Matrix.Visible := True;
  123.   end;
  124. end;
  125.  
  126. procedure TForm1.ElementAClick(Sender: TObject);
  127. Var
  128.   Str: String;
  129. begin
  130.   Help.Visible := True;
  131.   SelectA := True;
  132.   Str := Help.Caption;
  133. end;
  134.  
  135. procedure TForm1.ElementBClick(Sender: TObject);
  136. begin
  137.   Help.Visible := True;
  138.   SelectB := True;
  139. end;
  140.  
  141. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  142. begin
  143.   CanClose := Application.MessageBox('Вы действительно хотите выйти?', 'Выход',
  144.     MB_YESNO + MB_ICONQUESTION) = ID_YES;
  145. end;
  146.  
  147. procedure TForm1.InputMChange(Sender: TObject);
  148. Const
  149.   STR1 = 'Элемент A';
  150.   STR2 = 'Элемент B';
  151. Var
  152.   I, J: Integer;
  153. begin
  154.   If (Length(InputM.Text) = 0) or (Length(InputN.Text) = 0) then
  155.     Create.Enabled := False
  156.   else
  157.     Create.Enabled := True;
  158.   For I := 0 to Matrix.ColCount - 1 do
  159.     For J := 0 to Matrix.RowCount - 1 do
  160.       Matrix.Cells[I, J] := '';
  161.   ElementA.Visible := False;
  162.   ElementB.Visible := False;
  163.   ElementA.Caption := STR1;
  164.   ElementB.Caption := STR2;
  165.   Help.Visible := False;
  166.   MaxPath.Visible := False;
  167.   Matrix.Options := Matrix.Options + [GoEditing];
  168. end;
  169.  
  170. procedure TForm1.InputMKeyPress(Sender: TObject; var Key: Char);
  171. begin
  172.   If (Key = #13) and (Create.Enabled) then
  173.     Create.Click;
  174.   If (Not(Key In ['1' .. '5', #08, #46])) Then
  175.     Key := #0;
  176.   If Key = '.' then
  177.     Key := Char(0);
  178. end;
  179.  
  180. procedure TForm1.InputNChange(Sender: TObject);
  181. Const
  182.   STR1 = 'Элемент A';
  183.   STR2 = 'Элемент B';
  184. Var
  185.   I, J: Integer;
  186. begin
  187.   If (Length(InputM.Text) = 0) or (Length(InputN.Text) = 0) then
  188.     Create.Enabled := False
  189.   else
  190.     Create.Enabled := True;
  191.   For I := 0 to Matrix.ColCount - 1 do
  192.     For J := 0 to Matrix.RowCount - 1 do
  193.       Matrix.Cells[I, J] := '';
  194.  
  195.   ElementA.Visible := False;
  196.   ElementB.Visible := False;
  197.   ElementA.Caption := STR1;
  198.   ElementB.Caption := STR2;
  199.   Help.Visible := False;
  200.   MaxPath.Visible := False;
  201.   Matrix.Options := Matrix.Options + [GoEditing];
  202. end;
  203.  
  204. procedure TForm1.InputNKeyPress(Sender: TObject; var Key: Char);
  205. begin
  206.   If (Key = #13) and (Create.Enabled) then
  207.     Create.Click;
  208.   If (Not(Key In ['1' .. '5', #08, #46])) Then
  209.     Key := #0;
  210.   If Key = '.' then
  211.     Key := Char(0);
  212. end;
  213.  
  214. procedure TForm1.MatrixKeyPress(Sender: TObject; var Key: Char);
  215. Var
  216.   I, J: Integer;
  217.   IsCorrect: Boolean;
  218. begin
  219.   If (Not(Key In ['0' .. '9', #08, #46, '-'])) Then
  220.     Key := #0;
  221.   If Key = '.' then
  222.     Key := Char(0);
  223.   With Sender As TStringGrid Do
  224.   Begin
  225.     If (Length(Matrix.Cells[Col, Row]) > 2) then
  226.       If (Not(Key In [#08, #46])) Then
  227.         Key := #0;
  228.     If (Length(Matrix.Cells[Col, Row]) > 0) and (Key = '-') then
  229.       Key := #0;
  230.   End;
  231. end;
  232.  
  233. procedure TForm1.MatrixSelectCell(Sender: TObject; ACol, ARow: Integer;
  234.   var CanSelect: Boolean);
  235. Const
  236.   STR1 = 'Элемент A';
  237.   STR2 = 'Элемент B';
  238. begin
  239.   If SelectA then
  240.   begin
  241.     I1 := ACol;
  242.     J1 := ARow;
  243.     ElementA.Caption := STR1 + ' [' + IntToStr(I1 + 1) + ', ' +
  244.       IntToStr(J1 + 1) + ']';
  245.     SelectA := False;
  246.     Matrix.Options := Matrix.Options - [GoEditing];
  247.   end;
  248.   If SelectB then
  249.   begin
  250.     I2 := ACol;
  251.     J2 := ARow;
  252.     ElementB.Caption := STR2 + ' [' + IntToStr(I2 + 1) + ', ' +
  253.       IntToStr(J2 + 1) + ']';
  254.     SelectB := False;
  255.     Matrix.Options := Matrix.Options - [GoEditing];
  256.   end;
  257.   If (ElementA.Caption <> STR1) and (ElementB.Caption <> STR2) then
  258.     MaxPath.Visible := True;
  259. end;
  260.  
  261. procedure TForm1.MatrixSetEditText(Sender: TObject; ACol, ARow: Integer;
  262.   const Value: string);
  263. Var
  264.   I, J: Integer;
  265.   IsCorrect: Boolean;
  266. begin
  267.   IsCorrect := True;
  268.   For I := 0 to Matrix.ColCount - 1 do
  269.     For J := 0 to Matrix.RowCount - 1 do
  270.       If (Length(Matrix.Cells[I, J]) = 0) Then
  271.       begin
  272.         ElementA.Visible := False;
  273.         ElementB.Visible := False;
  274.         IsCorrect := False;
  275.         Break;
  276.       end;
  277.   If IsCorrect then
  278.   begin
  279.     ElementA.Visible := True;
  280.     ElementB.Visible := True;
  281.   end;
  282.  
  283. end;
  284.  
  285. Function IsValid(I, J, N, M: Integer; const BoolMatrix: TBoolMatrix): Boolean;
  286. Begin
  287.   Result := (I >= 0) and (I < N) and (J >= 0) and (J < M) and
  288.     (Not BoolMatrix[I, J]);
  289. End;
  290.  
  291. Function TrueCopy(BoolMatrix: TBoolMatrix): TBoolMatrix;
  292. Var
  293.   I, J: Integer;
  294. Begin
  295.   SetLength(Result, Length(BoolMatrix), Length(BoolMatrix[0]));
  296.   For I := Low(BoolMatrix) to High(BoolMatrix) do
  297.     For J := Low(BoolMatrix[I]) to High(BoolMatrix[I]) do
  298.     Begin
  299.       Result[I][J] := BoolMatrix[I][J];
  300.     End;
  301. End;
  302.  
  303. Function FindPaths2(Const Matrix: TMatrix; BoolMatrix: TBoolMatrix;
  304.   Var Path: TPath; X, Y: Integer): Integer;
  305. Var
  306.   Sum: Integer;
  307.   Max1, Max2, Max3, Max4: Integer;
  308.   Path1, Path2, Path3, Path4: TPath;
  309.   I, J: Integer;
  310. Begin
  311.   BoolMatrix[X, Y] := True;
  312.   SetLength(Path, Length(Path) + 1);
  313.   Path[High(Path)].X := X;
  314.   Path[High(Path)].Y := Y;
  315.  
  316.   If (X = FinishRowPoint) and (Y = FinishColPoint) then
  317.   begin
  318.     Result := Matrix[X, Y].Elem;
  319.   end
  320.   else
  321.   Begin
  322.     Path1 := Copy(Path);
  323.     Path2 := Copy(Path);
  324.     Path3 := Copy(Path);
  325.     Path4 := Copy(Path);
  326.  
  327.     Max1 := Integer.MinValue;
  328.     Max2 := Integer.MinValue;
  329.     Max3 := Integer.MinValue;
  330.     Max4 := Integer.MinValue;
  331.  
  332.     // move up
  333.     If (IsValid(X - 1, Y, N, M, BoolMatrix)) then
  334.     Begin
  335.       Max1 := FindPaths2(Matrix, TrueCopy(BoolMatrix), Path1, X - 1, Y);
  336.     End;
  337.  
  338.     // move down
  339.     If (IsValid(X + 1, Y, N, M, BoolMatrix)) then
  340.     Begin
  341.       Max2 := FindPaths2(Matrix, TrueCopy(BoolMatrix), Path2, X + 1, Y);
  342.     End;
  343.  
  344.     // move left
  345.     If (IsValid(X, Y - 1, N, M, BoolMatrix)) then
  346.     Begin
  347.       Max3 := FindPaths2(Matrix, TrueCopy(BoolMatrix), Path3, X, Y - 1);
  348.     End;
  349.  
  350.     // move right
  351.     If (IsValid(X, Y + 1, N, M, BoolMatrix)) then
  352.     Begin
  353.       Max4 := FindPaths2(Matrix, TrueCopy(BoolMatrix), Path4, X, Y + 1);
  354.     End;
  355.  
  356.     Path := Path1;
  357.  
  358.     If (Max2 > Max1) then
  359.     Begin
  360.       Path := Path2;
  361.       Max1 := Max2;
  362.     end;
  363.     If (Max3 > Max1) then
  364.     Begin
  365.       Path := Path3;
  366.       Max1 := Max3;
  367.     End;
  368.     If (Max4 > Max1) then
  369.     Begin
  370.       Path := Path4;
  371.       Max1 := Max4;
  372.     End;
  373.     If (Max1 = Integer.MinValue) then
  374.       Result := Max1
  375.     Else
  376.       Result := Max1 + Matrix[X, Y].Elem;
  377.   End;
  378. End;
  379.  
  380. procedure TForm1.MaxPathClick(Sender: TObject);
  381. Var
  382.   I, J, Max: Integer;
  383.   IsCorrect: Boolean;
  384.   Vertex: Char;
  385.   Index: Byte;
  386.   BoolMatrix: TBoolMatrix;
  387. Const
  388.   STR1 = 'Элемент A';
  389.   STR2 = 'Элемент B';
  390. begin
  391.   IsCorrect := True;
  392.   Index := 1;
  393.   If IsCorrect then
  394.   begin
  395.     try
  396.       For I := 0 to Matrix.ColCount - 1 do
  397.         For J := 0 to Matrix.RowCount - 1 do
  398.         Begin
  399.           Arr[J, I].Elem := StrToInt(Matrix.Cells[I, J]);
  400.           Arr[J, I].I := Index;
  401.           Inc(Index);
  402.         End;
  403.     except
  404.       IsCorrect := False;
  405.       MessageBox(Form1.Handle,
  406.         Pchar('Проверьте содержимое матрицы. В клеточках должны быть только целочисленные значения.'),
  407.         'Ошибка', MB_ICONSTOP);
  408.       ElementA.Visible := False;
  409.       ElementB.Visible := False;
  410.       ElementA.Caption := STR1;
  411.       ElementB.Caption := STR2;
  412.       Help.Visible := False;
  413.       MaxPath.Visible := False;
  414.       Matrix.Options := Matrix.Options + [GoEditing];
  415.     end;
  416.   end;
  417.   If IsCorrect then
  418.   begin
  419.     SetLength(BoolMatrix, M, N);
  420.     For I := 0 to M - 1 do
  421.     Begin
  422.       For J := 0 to N - 1 do
  423.       Begin
  424.         BoolMatrix[I, J] := False;
  425.       End;
  426.     End;
  427.     SetLength(Path, 0);
  428.     FinishRowPoint := I2;
  429.     FinishColPoint := J2;
  430.     StartRowPoint := I1;
  431.     StartColPoint := J1;
  432.     Max := FindPaths2(Arr, BoolMatrix, Path, StartRowPoint, StartColPoint);
  433.     For I := 0 to Matrix.ColCount - 1 do
  434.       For J := 0 to Matrix.RowCount - 1 do
  435.       Begin
  436.         Matrix.Cells[I, J] := '';
  437.       End;
  438.     PathLabel.Caption := PathLabel.Caption + IntToStr(Max);
  439.     PathLabel.Visible := True;
  440.     I := 0;
  441.     Timer1.Enabled := True;
  442.   end;
  443. end;
  444.  
  445. Function Open(): String;
  446. Begin
  447.   With Form1 Do
  448.   Begin
  449.     If OpenDialog1.Execute Then
  450.     Begin
  451.       FilePath := OpenDialog1.FileName;
  452.       IsFileOpen := True;
  453.     End
  454.     Else
  455.       IsFileOpen := False;
  456.   End;
  457.   Open := FilePath;
  458. End;
  459.  
  460. Function CheckFileDataForN(Num: String; Max, MIN: Integer): Boolean;
  461. Var
  462.   NewNum: Integer;
  463.   IsCorrect: Boolean;
  464. Begin
  465.   NewNum := 0;
  466.   IsCorrect := True;
  467.   Num := Trim(Num);
  468.   Try
  469.     NewNum := StrToInt(Num);
  470.   Except
  471.     MessageBox(Form1.Handle,
  472.       Pchar('Не получилось преобразовать N к целочисленному типу данных. Проверьте корректность данных.'),
  473.       'Ошибка', MB_ICONSTOP);
  474.     IsCorrect := False;
  475.   End;
  476.   If (IsCorrect And ((NewNum > Max) Or (NewNum < MIN))) Then
  477.   Begin
  478.     Num := IntToStr(NewNum);
  479.     MessageBox(Form1.Handle,
  480.       Pchar('N вне разрешенного диапазона! Проверьте исходные данные.'),
  481.       'Ошибка', MB_ICONSTOP);
  482.     IsCorrect := False;
  483.   End;
  484.   CheckFileDataForN := IsCorrect;
  485. End;
  486.  
  487. Function TakeDataFromFile2(Number2: String; Var FileOutput: TextFile;
  488.   Max, MIN: Integer): String;
  489. Var
  490.   IsRight: Boolean;
  491. Begin
  492.   IsRight := True;
  493.   Try
  494.     Readln(FileOutput, Number2);
  495.     Number2 := Trim(Number2);
  496.     IsRight := CheckFileDataForN(Number2, Max, MIN);
  497.   Except
  498.   End;
  499.   If (Not(IsRight)) Then
  500.     TakeDataFromFile2 := ''
  501.   Else
  502.     TakeDataFromFile2 := Number2;
  503. End;
  504.  
  505. function SeparateString(Str: String): TStr;
  506. Var
  507.   StrArr: TStr;
  508.   I, K: Integer;
  509.   Flag: Boolean;
  510. Begin
  511.   K := 0;
  512.   SetLength(StrArr, (Str.Length div 2) + 1);
  513.   For I := 0 To Str.Length div 2 do
  514.     StrArr[I] := '';
  515.   I := 1;
  516.   While I <= Str.Length Do
  517.   begin
  518.     Flag := True;
  519.     While (Str[I] <> ' ') and (I <= Str.Length) Do
  520.     Begin
  521.       StrArr[K] := StrArr[K] + Str[I];
  522.       Inc(I);
  523.       Flag := False;
  524.     End;
  525.     If Not(Flag) then
  526.       Inc(K);
  527.     If Flag then
  528.       Inc(I);
  529.   end;
  530.   I := 1;
  531.   K := 0;
  532.   While Str[I] <> '' Do
  533.   Begin
  534.     If Str[I] = ' ' then
  535.       Inc(K);
  536.     Inc(I);
  537.   End;
  538.   SetLength(StrArr, K + 1);
  539.   Result := StrArr;
  540. End;
  541.  
  542. function ConvertStringToArray(StringGridColCount: Integer;
  543.   Var FileOutput: TextFile): TArray;
  544. Var
  545.   I: Integer;
  546.   Arr: TArray;
  547.   Str: String;
  548.   StrArr: TStr;
  549. Const
  550.   MIN = -99;
  551.   Max = 999;
  552.   BAD = 1000;
  553. Begin
  554.   Readln(FileOutput, Str);
  555.   SetLength(Arr, StringGridColCount);
  556.   for I := Low(Arr) to High(Arr) do
  557.     Arr[I] := 0;
  558.   Str := Trim(Str);
  559.   StrArr := SeparateString(Str);
  560.   If (High(StrArr) + 1 <> StringGridColCount) then
  561.   begin
  562.     SetLength(Arr, 1);
  563.     Arr[0] := BAD;
  564.     MessageBox(Form1.Handle,
  565.       Pchar('Количество элементов массива не совпадает с заявленным. Проверьте исходные данные.'),
  566.       'Ошибка', MB_ICONSTOP);
  567.     ConvertStringToArray := Arr;
  568.     Exit
  569.   end;
  570.   try
  571.     For I := Low(Arr) to High(Arr) do
  572.       Arr[I] := StrToInt(StrArr[I]);
  573.   except
  574.     SetLength(Arr, 1);
  575.     Arr[0] := BAD;
  576.     MessageBox(Form1.Handle,
  577.       Pchar('Не удалось преобразовать исходные данные в целочисленный тип. Проверьте исходные данные.'),
  578.       'Ошибка', MB_ICONSTOP);
  579.     ConvertStringToArray := Arr;
  580.     Exit
  581.   end;
  582.   For I := Low(Arr) to High(Arr) do
  583.     If (Arr[I] > Max) or (Arr[I] < MIN) then
  584.     begin
  585.       SetLength(Arr, 1);
  586.       Arr[0] := BAD;
  587.       MessageBox(Form1.Handle,
  588.         Pchar('Исходные данные выходят за границы допустимых. Проверьте исходные данные.'),
  589.         'Ошибка', MB_ICONSTOP);
  590.       ConvertStringToArray := Arr;
  591.     end;
  592.   ConvertStringToArray := Arr;
  593. End;
  594.  
  595. procedure TForm1.N2Click(Sender: TObject);
  596. Var
  597.   FileInput: TextFile;
  598.   Num, I, J: Integer;
  599.   STR1, STR2: String;
  600.   Arr: TArray;
  601.   IsCorrect: Boolean;
  602. Const
  603.   MAX_ARR = 5;
  604.   MIN_ARR = 1;
  605.   Max = 999;
  606.   MIN = -99;
  607.   BAD = 1000;
  608. begin
  609.   Num := 0;
  610.   FilePath := Open();
  611.   AssignFile(FileInput, FilePath);
  612.   Reset(FileInput);
  613.   If (IsFileOpen) Then
  614.   Begin
  615.     STR1 := TakeDataFromFile2(IntToStr(Num), FileInput, MAX_ARR, MIN_ARR);
  616.   End;
  617.   if Not(STR1 = '') then
  618.   Begin
  619.     STR2 := TakeDataFromFile2(IntToStr(Num), FileInput, MAX_ARR, MIN_ARR)
  620.   End;
  621.   if ((STR1 <> '') and (STR2 <> '')) then
  622.   begin
  623.     InputM.Text := STR1;
  624.     InputN.Text := STR2;
  625.     M := StrToInt(STR1);
  626.     N := StrToInt(STR2);
  627.     Create.Click;
  628.     IsCorrect := True;
  629.     For J := 0 To M - 1 Do
  630.     Begin
  631.       Arr := ConvertStringToArray(StrToInt(STR2), FileInput);
  632.       if (Arr[0] <> BAD) then
  633.       Begin
  634.         for I := Low(Arr) to High(Arr) do
  635.         Begin
  636.           Matrix.Cells[I, J] := IntToStr(Arr[I]);
  637.         End;
  638.       End
  639.       else
  640.       Begin
  641.         for I := Low(Arr) to StrToInt(STR1) - 1 do
  642.         Begin
  643.           Matrix.Cells[I, J] := '';
  644.           IsCorrect := False;
  645.         End;
  646.       End;
  647.     End;
  648.     If IsCorrect then
  649.     begin
  650.       ElementA.Visible := True;
  651.       ElementB.Visible := True;
  652.     end;
  653.  
  654.   end;
  655. end;
  656.  
  657. procedure TForm1.N4Click(Sender: TObject);
  658. begin
  659.   Application.MessageBox
  660.     ('Дана матрица a(m,n). Найти в ней путь от элемента a[i1,j1] до элемента a[i2,j2] с максимальной суммой. Ходить можно по горизонталям и вертикалям. Каждый элемент матрицы может входить в путь не более одного раза. Выделить этот путь в матрице!',
  661.     'Задание', MB_ICONINFORMATION);
  662. end;
  663.  
  664. procedure TForm1.N5Click(Sender: TObject);
  665. begin
  666.   Application.MessageBox('Студент группы 251004 Асепков Данила', 'О разрабочике', MB_ICONINFORMATION);
  667. end;
  668.  
  669. procedure TForm1.Timer1Timer(Sender: TObject);
  670. begin
  671.   If I <= High(Path) then
  672.   begin
  673.     Matrix.Cells[Path[I].X, Path[I].Y] :=
  674.       IntToStr(Arr[Path[I].X, Path[I].Y].Elem);
  675.     Inc(I);
  676.   end
  677.   else
  678.     Timer1.Enabled := False;
  679. end;
  680.  
  681. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement