HEX0x29A

Удалить строку из динамического массива

Dec 5th, 2019
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.77 KB | None | 0 0
  1. program Project2;
  2.  
  3. uses
  4.   SysUtils;
  5.  
  6. type
  7.   TArrayOfString = array of string;
  8.  
  9. procedure Rand(var a: TArrayOfString);
  10. var
  11.   i: Integer;
  12. begin
  13.   SetLength(a, Succ(Random(10)));
  14.   for i := Low(a) to High(a) do
  15.     a[i] := IntToStr(Random(MaxInt));
  16. end;
  17.  
  18. procedure Print(a: TArrayOfString);
  19. var
  20.   i: Integer;
  21. begin
  22.   for i := Low(a) to High(a) do
  23.     WriteLn(i, #9, a[i]);
  24. end;
  25.  
  26. procedure Delete(var a: TArrayOfString; Index: Word);
  27. var
  28.   i: Integer;
  29. begin
  30.   for i := Index to Pred(High(a)) do
  31.     a[i] := a[Succ(i)];
  32.   SetLength(a, Pred(Length(a)));
  33. end;
  34.  
  35. var
  36.   n: Integer;
  37.   a: TArrayOfString;
  38.  
  39. begin
  40.   Randomize;
  41.   Rand(a);
  42.   Print(a);
  43.   WriteLn;
  44.   n := Random(Length(a));
  45.   WriteLn('Delete ', n);
  46.   Delete(a, n);
  47.   Print(a);
  48.   ReadLn;
  49. end.
Add Comment
Please, Sign In to add comment