Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TLab4_2.pall (i, j, t:integer; a: mas):boolean;
- begin
- pall := true;
- if t = j - i + 1 div 2 then
- else
- if a[i+t] = a [j - t] then
- pall := pall(i, j, t + 1, a)
- else
- pall := false;
- end;
- procedure TLab4_2.sub(n: Integer; a: mas; var k, pos1, pos2: Integer);
- var
- i, max, j: Integer;
- begin
- max := 0;
- pos1 := 0;
- pos2 := 0;
- for i := 1 to n - 1 do
- for j := i + 1 to n do
- if pall(i, j, 0, a) then
- if j - i + 1 > max then
- begin
- max := j - i + 1;
- pos1 := i;
- pos2 := j;
- end;
- k := max;
- end;
- procedure TLab4_2.EnterClick(Sender: TObject);
- var
- n, i, k, pos1, pos2: Integer;
- a: mas;
- NotEmpty: Boolean;
- begin
- NotEmpty := True;
- for i := 0 to InputGrid.RowCount - 1 do
- if InputGrid.Cells[0, i] = '' then
- NotEmpty := False;
- if (QuantEdit.Text <> '') and (NotEmpty) then
- begin
- try
- n := StrToInt(QuantEdit.Text);
- for i := 1 to n do
- a[i] := StrToInt(InputGrid.Cells[0, i - 1]);
- sub(n,a,k, pos1, pos2);
- if k <> 0 then
- begin
- Result := TResult.Create(Self);
- Result.OutputGrid.RowCount := pos2 - pos1 + 1;
- for i := pos1 to pos2 do
- Result.OutputGrid.Cells[0, i - pos1] := IntToStr(a[i]);
- Result.FirstPos.Text := IntToStr(pos1);
- Result.LastPos.Text := IntToStr(pos2);
- Result.ShowModal;
- end
- else
- if k = 0 then
- MessageBox(handle, PChar('There Are Not Any Palindroms In This Array!'), PChar('INFO'), MB_OK + MB_ICONINFORMATION);
- except
- MessageBox(handle, PChar('Enter all edits.'), PChar('ERROR'), MB_OK + MB_ICONERROR);
- end;
- end
- else
- MessageBox(handle, PChar('Enter all edits.'), PChar('ERROR'), MB_OK + MB_ICONERROR);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement