Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.78 KB | None | 0 0
  1. program Project8;
  2.  
  3. {$APPTYPE CONSOLE}
  4. {$R *.res}
  5.  
  6. uses
  7.   System.SysUtils;
  8.  
  9.  
  10. Function Answering( M : integer; N : integer) : integer;
  11. var
  12.   F: extended;
  13. begin
  14.   if (M = 0) then
  15.     Answering := N + 1;
  16.   if (M > 0) and (N = 0) then
  17.     Answering := Answering(M - 1, 1)
  18.   else if (M > 0) and ( N > 0) then
  19.     Answering := Answering(M - 1 ,Answering(M, N - 1));
  20. end;
  21.  
  22. Function FindingFile(): integer;
  23. var
  24.   CorrectFile: Boolean;
  25.   NameOfFile: String;
  26.   Input : TextFile;
  27.   M, N,F : integer;
  28. begin
  29.   repeat
  30.     Write('Введите путь к файлу, с которого хотите считать информацию :');
  31.     Readln(NameOfFile);
  32.     CorrectFile := True;
  33.     try
  34.       AssignFile(Input, NameOfFile);
  35.       Reset(Input);
  36.       if not eof(Input) then
  37.          begin
  38.             ReadLn(Input, M);
  39.             Read(Input, N);
  40.             CloseFile(Input);
  41.          end
  42.       else
  43.          begin
  44.             WriteLn(' Файл оказался пустым ');
  45.             CloseFile(Input) ;
  46.          end;
  47.     except
  48.       CorrectFile := False;
  49.       Writeln('Не удалось найти файл по такому пути', NameOfFile);
  50.     end;
  51.   until CorrectFile;
  52.   F := Answering(M,N);
  53.   WriteLn(F);
  54.   result := F;
  55. end;
  56.  
  57.  
  58. Procedure SaveFile(NameOutput : String ; F: integer);
  59. var
  60.   Output: TextFile;
  61.   begin
  62.      Writeln('Введите путь к файлу для записи : ');
  63.      Readln(NameOutput);
  64.      AssignFile(Output,NameOutput);
  65.      Rewrite(Output);
  66.      WriteLn(Output , 'Ответ :', F);
  67.      CloseFile(Output);
  68.      ReadLn;
  69.   end;
  70.  
  71. var
  72.   F , M , N : integer;
  73.   CorrectFile: Boolean;
  74.   NameOfFile: String;
  75.   NameOutput : String;
  76. begin
  77.   F := FindingFile();
  78.   SaveFile(NameOutput, F);
  79.   ReadLn;
  80. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement