Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.19 KB | None | 0 0
  1. program Project23;
  2.  
  3.  
  4. {$APPTYPE CONSOLE}
  5. {$R *.res}
  6.  
  7. uses
  8.    System.SysUtils;
  9. Type
  10.    TArr = set of byte ;
  11.  
  12. procedure FindingFile( var X : TArr);
  13. var
  14.    CorrectFile: Boolean;
  15.    NameOfFile : String;
  16.    Input : TextFile;
  17.    i, n: byte ;
  18.    Reader : array of integer;
  19. begin
  20.    repeat
  21.      Write('Введите путь к файлу, с которого хотите считать информацию :');
  22.      Readln(NameOfFile);
  23.      CorrectFile := True;
  24.      try
  25.         AssignFile(Input, NameOfFile);
  26.         Reset(Input);
  27.         if not eof(Input) then
  28.         begin
  29.            ReadLn(Input, n);
  30.            SetLength(Reader , n);
  31.            for i := 0 to n-1 do
  32.            begin
  33.               Read(Input,Reader[i]);
  34.               Include( X, Reader[i]);
  35.            end;
  36.            CloseFile(Input);
  37.         end
  38.         else
  39.         begin
  40.            WriteLn(' Файл оказался пустым ');
  41.            CloseFile(Input) ;
  42.         end;
  43.     except
  44.        CorrectFile := False;
  45.        Writeln('Не удалось найти файл по такому пути', NameOfFile);
  46.     end;
  47.   until CorrectFile;
  48. end;
  49.  
  50. function Union( var X1, X2 : TArr): TArr;
  51. var
  52.    Y , X: TArr ;
  53. begin
  54.    Y := X1 + X2;
  55.    Union := Y;
  56. end;
  57.  
  58. function EvenElements(var Y : TArr) : TArr;
  59. var
  60.    Y1 : TArr;
  61.    i : integer;
  62. begin
  63.    Y1 := [];
  64.    for i := 0 to 255 do
  65.    begin
  66.       if (i in Y) then
  67.       begin
  68.          if (i mod 2 = 0) then
  69.             Y1 := Y1 + [i] ;
  70.       end;
  71.    end;
  72.    EvenElements := Y1;
  73. end;
  74.  
  75. procedure SaveFile(NameOutput : String ; var Y1: TArr );
  76. var
  77.    Output: TextFile;
  78.    i : integer ;
  79.    begin
  80.       Writeln('Введите путь к файлу для записи : ');
  81.       Readln(NameOutput);
  82.       AssignFile(Output,NameOutput);
  83.       Rewrite(Output);
  84.       for i := 0 to 255 do
  85.       begin
  86.          if i in Y1 then
  87.             Write( Output, i , ' ');
  88.       end;
  89.       WriteLn(Output);
  90.       CloseFile(Output);
  91.    end;
  92.  
  93. var
  94.    Y1 , X1 , X2 , Y : TArr;
  95.    NameOutput : String;
  96. begin
  97.    FindingFile(X1);
  98.    FindingFile(X2);
  99.    Y := Union (X1, X2);
  100.    Y1 := EvenElements(Y);
  101.    SaveFile(NameOutput, Y1);
  102.    ReadLn;
  103. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement