Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.43 KB | None | 0 0
  1. program project1;
  2.  
  3. uses
  4.     SysUtils, Windows
  5.   { you can add units after this };
  6.  
  7. const
  8.   filename = 'input.txt';
  9.   N = 10;
  10.   region_max = 99;
  11.  
  12. type
  13.    address = record
  14.     street: string[20];
  15.     home_num: integer;
  16.     flat_num: integer;
  17.   end;
  18.  
  19.   edition = record
  20.     title: string[20];
  21.     is_magazine: boolean;
  22.     monthes: array [1..12] of boolean;
  23.   end;
  24.  
  25.   subscriber = record
  26.     fio: string[20];
  27.     target: 1..region_max; {участок доставки}
  28.     the_address: address;
  29.     count: integer;
  30.     editions: array [1..N] of edition;
  31.   end;
  32.  
  33.   AllRegions = array [1..region_max] of integer;
  34.  
  35.  
  36. function readStruct(var f: textFile): subscriber;
  37. var
  38.   s: String;
  39.   //res: subscriber;
  40.   cnt, b, e: integer;
  41.   i, j: integer;
  42. begin
  43.   readln(f, result.fio);
  44.   readln(f, s);
  45.   result.target:=strToInt(s);
  46.   readln(f, s); {Count of editions subscribe}
  47.   cnt := strToInt(s);
  48.   result.count := cnt;
  49.  
  50.   {address block}
  51.   readln(f, result.the_address.street);
  52.   readln(f, s);
  53.   result.the_address.home_num :=strToInt(s);
  54.   readln(f, s);
  55.   result.the_address.flat_num :=strToInt(s);
  56.  
  57.   {edition block}
  58.   for i := 1 to cnt do begin
  59.     readln(f, result.editions[i].title);
  60.     readln(f, s);
  61.     result.editions[i].is_magazine := s = 't';
  62.     readln(f, s);
  63.     b := StrToInt(copy(s, 1, pos('-', s)-1));
  64.     e := StrToInt(copy(s, pos('-',s) + 1, length(s)));
  65.     for j := b to e do begin
  66.       result.editions[i].monthes[j] := true;
  67.     end
  68.   end;
  69.  
  70. end;
  71.  
  72. var
  73.   f : TextFile;
  74.   person: subscriber;
  75.  
  76.   s: String;
  77.  
  78.   prevFIO : string;
  79.   Cnt : integer;
  80.  
  81.   resFIO : string;
  82.   resCnt : integer;
  83.   begin
  84.      SetconsoleCP(1251);
  85.      SetconsoleOutputCP(1251);
  86.  
  87.      AssignFile(f, filename);
  88.      // Open the file for reading
  89.      reset(f);
  90.  
  91.      resFIO := '';
  92.      resCnt := 0;
  93.      prevFIO:= '';
  94.      Cnt := 0;
  95.      while not eof(f) do
  96.      begin
  97.        person := readStruct(f);
  98.        writeln('Person: ', person.fio, ' cnt: ', person.count);
  99.        if not eof(f) then
  100.               readln(f, s);
  101.  
  102.        if person.FIO = prevFIO
  103.               then Cnt := Cnt + person.count
  104.               else Cnt := person.count;
  105.  
  106.        prevFIO := person.FIO;
  107.  
  108.        if Cnt > resCnt then begin
  109.                   resCnt := Cnt;
  110.                   resFIO := prevFIO;
  111.                 end;
  112.  
  113.  
  114.        writeln('***'+#13+#10);
  115.      end;
  116.  
  117.      CloseFile(f);
  118.  
  119.      Writeln(ResFIO) ;
  120.      Readln;
  121. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement