Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.88 KB | None | 0 0
  1. function TLab4_2.pall (i, j, t:integer; a: mas):boolean;
  2. begin
  3.    pall := true;
  4.    if t = j - i + 1 div 2 then
  5.    else
  6.       if a[i+t] = a [j - t] then
  7.          pall := pall(i, j, t + 1, a)
  8.       else
  9.          pall := false;
  10. end;
  11.  
  12. procedure TLab4_2.sub(n: Integer; a: mas; var k, pos1, pos2: Integer);
  13. var
  14.    i, max, j: Integer;
  15. begin
  16.    max := 0;
  17.    pos1 := 0;
  18.    pos2 := 0;
  19.    for i := 1 to n - 1  do
  20.       for j := i + 1 to n  do
  21.       if pall(i, j, 0, a) then
  22.          if j - i + 1 > max then
  23.          begin
  24.             max := j - i + 1;
  25.             pos1 := i;
  26.             pos2 := j;
  27.          end;
  28.  
  29.  
  30.    k := max;
  31. end;
  32.  
  33. procedure TLab4_2.EnterClick(Sender: TObject);
  34. var
  35.    n, i, k, pos1, pos2: Integer;
  36.    a: mas;
  37.    NotEmpty: Boolean;
  38. begin
  39.    NotEmpty := True;
  40.    for i := 0 to InputGrid.RowCount - 1 do
  41.       if InputGrid.Cells[0, i] = '' then
  42.          NotEmpty := False;
  43.    if (QuantEdit.Text <> '') and (NotEmpty) then
  44.    begin
  45.       try
  46.       n := StrToInt(QuantEdit.Text);
  47.       for i := 1 to n do
  48.          a[i] := StrToInt(InputGrid.Cells[0, i - 1]);
  49.       sub(n,a,k, pos1, pos2);
  50.       if k <> 0 then
  51.       begin
  52.          Result := TResult.Create(Self);
  53.          Result.OutputGrid.RowCount := pos2 - pos1 + 1;
  54.          for i := pos1 to pos2 do
  55.             Result.OutputGrid.Cells[0, i - pos1] := IntToStr(a[i]);
  56.          Result.FirstPos.Text := IntToStr(pos1);
  57.          Result.LastPos.Text := IntToStr(pos2);
  58.          Result.ShowModal;
  59.       end
  60.       else
  61.          if k = 0 then
  62.             MessageBox(handle, PChar('There Are Not Any Palindroms In This Array!'), PChar('INFO'), MB_OK + MB_ICONINFORMATION);
  63.       except
  64.          MessageBox(handle, PChar('Enter all edits.'), PChar('ERROR'), MB_OK + MB_ICONERROR);
  65.       end;
  66.    end
  67.    else
  68.       MessageBox(handle, PChar('Enter all edits.'), PChar('ERROR'), MB_OK + MB_ICONERROR);
  69.  
  70. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement