Advertisement
Samatter

Benedict.pas

Jan 4th, 2019 (edited)
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.34 KB | None | 0 0
  1. program Benedict;
  2.  
  3. const FFName = '01_01.txt';
  4. const FSName = '01_02.txt';
  5. const SFName = '02_01.txt';
  6. const SSName = '02_02.txt';
  7. const OutputName = 'BenedictOutput.txt';
  8. var FFFile, FSFile, SFFile, SSFile, OutputFile: TextFile;
  9.  
  10. begin
  11.   var NMax, wNum: integer;
  12.   writeln('How many? With numbers (0/1)?');
  13.   readln(NMax, wNum);
  14.   if (NMax < 1) or ((wNum <> 0) and (wNum <> 1)) then
  15.   begin
  16.     write('Error!');
  17.     readln;
  18.     exit;
  19.   end;
  20.  
  21.   var FFArray: array[0..999] of string;
  22.   AssignFile(FFFile, FFName);
  23.   reset(FFFile);
  24.   var FFCount: integer = 0;
  25.   while not eof(FFFile) do
  26.   begin
  27.     readln(FFFile, FFArray[FFCount]);
  28.     FFCount := FFCount + 1;
  29.   end;
  30.   CloseFile(FFFile);
  31.  
  32.   var FSArray: array[0..999] of string;
  33.   AssignFile(FSFile, FSName);
  34.   reset(FSFile);
  35.   var FSCount: integer = 0;
  36.   while not eof(FSFile) do
  37.   begin
  38.     readln(FSFile, FSArray[FSCount]);
  39.     FSCount := FSCount + 1;
  40.   end;
  41.   CloseFile(FSFile);
  42.  
  43.   var SFArray: array[0..999] of string;
  44.   AssignFile(SFFile, SFName);
  45.   reset(SFFile);
  46.   var SFCount: integer = 0;
  47.   while not eof(SFFile) do
  48.   begin
  49.     readln(SFFile, SFArray[SFCount]);
  50.     SFCount := SFCount + 1;
  51.   end;
  52.   CloseFile(SFFile);
  53.  
  54.   var SSArray: array[0..999] of string;
  55.   AssignFile(SSFile, SSName);
  56.   reset(SSFile);
  57.   var SSCount: integer = 0;
  58.   while not eof(SSFile) do
  59.   begin
  60.     readln(SSFile, SSArray[SSCount]);
  61.     SSCount := SSCount + 1;
  62.   end;
  63.   CloseFile(SSFile);
  64.  
  65.   AssignFile(OutputFile, OutputName);
  66.   rewrite(OutputFile);
  67.  
  68.   var Temp: integer;
  69.   var sNMax: string;
  70.   var sNMaxLength: integer;
  71.   var sN: string;
  72.   var sNLength: integer;
  73.   str(NMax, sNMax);
  74.   sNMaxLength := sNMax.Length;
  75.   for var N := 1 to NMax do
  76.   begin
  77.     if (wNum = 1) then
  78.     begin
  79.       str(N, sN);
  80.       sNLength := sN.Length;
  81.       while sNLength < sNMaxLength do
  82.       begin
  83.         sN := '0' + sN;
  84.         sNLength := sNLength + 1;
  85.       end;
  86.       write(OutputFile, sN, ') ');
  87.     end;
  88.    
  89.     Temp:=random(FFCount);
  90.     write(OutputFile, FFArray[Temp]);
  91.    
  92.     Temp:=random(FSCount);
  93.     write(OutputFile, FSArray[Temp], ' ');
  94.    
  95.     Temp:=random(SFCount);
  96.     write(OutputFile, SFArray[Temp]);
  97.    
  98.     Temp:=random(SSCount);
  99.     writeln(OutputFile, SSArray[Temp]);
  100.   end;
  101.  
  102.   CloseFile(OutputFile);
  103.   write('Done!');
  104.   readln;
  105. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement