{I. 247.}
{Gema Barnabs}
{Veszprm, Lovassy Lszl Gimnzium}
{e-mail: lyuki2@freemail.hu}
{FreePascal 2.2.0}
program i247;
uses crt;
type lepes = record
              orakulso:byte;
              perckulso:byte;
              seckulso:byte;
              orabelso:byte;
              percbelso:byte;
              secbelso:byte;
              rendszam:string;
              irany:string;
             end;
     ido = record
            rendszam:string;
            ora:integer;
            perc:integer;
            sec:integer;
            orabe:byte;
            percbe:byte;
            secbe:byte;
            ki:boolean;
           end;
var adat:array[1..5000] of lepes;
    auto:array[1..5000] of ido;
    x,n,c:integer;




procedure feladat1;
var f:text;

Begin
 writeln('1. feladat');
{adatok beolvassa a megfelel adatszerkezetbe}
 assign(f,'parkolo.be');
 {$I-}
 reset(f);
 {$I+}
{hiba esetn lellts}
 if IOResult<>0 then begin
  writeln('Hiba! Nincs meg a fjl!');
  halt;
 end;
 x:=1;
{rekordok beolvassa}
 while not eof(f) do begin
  read(f,adat[x].orakulso);
  read(f,adat[x].perckulso);
  read(f,adat[x].seckulso);
  read(f,adat[x].orabelso);
  read(f,adat[x].percbelso);
  read(f,adat[x].secbelso);
  readln(f,adat[x].rendszam);
  inc(x);
 end;
{n lesz a bemeneti adat rekordjainak szma}
 n:=x-1;
 close(f);
 writeln('Adatok beolvasva.');
End;


procedure feladat2;

Begin
 writeln('2. feladat');
{A ciklusban a program elszr az rt, utna a percet, utna a msodpercet
nzi meg. Ha valamelyik alapjn nem dnthet el egyrtelmen az irny, akkor
nzi csak meg a kvetezt. Eltroltam az irnyokat, mert ksbb mg szksg
lesz r.}
 for x:=1 to n do begin
  if adat[x].orabelso>adat[x].orakulso then adat[x].irany:='Be'
   else if adat[x].orabelso<adat[x].orakulso then adat[x].irany:='Ki'
    else if adat[x].percbelso>adat[x].perckulso then adat[x].irany:='Be'
     else if adat[x].percbelso<adat[x].perckulso then adat[x].irany:='Ki'
      else if adat[x].secbelso>adat[x].seckulso then adat[x].irany:='Be'
       else if adat[x].secbelso<adat[x].seckulso then adat[x].irany:='Ki'
        else adat[x].irany:='???';
 end;
{irny kirsa}
 for x:=1 to n do writeln(adat[x].rendszam,' ',adat[x].irany);
End;


procedure feladat3;
var ora:array[0..23] of integer;
    max,maxora:integer;

Begin
 writeln('3. feladat');
{Minden rban az autk szmnak belltsa 0-ra}
 for x:=0 to 23 do ora[x]:=0;
{Minden rra szmols}
 for x:=1 to n do
  if adat[x].irany='Be' then inc(ora[adat[x].orakulso]);
{maximum megkeresse}
 max:=-1;
 for x:=0 to 23 do if ora[x]>max then begin
  max:=ora[x];
  maxora:=x;
 end;
{legforgalmasabb ra kirsa}
 writeln(maxora);
End;




procedure feladat4;
var y:integer;
    b:boolean;

Begin
 writeln('4.feladat');
 c:=0;
{minden rendszm vgignzse}
 for x:=1 to n do begin
  b:=false;
  y:=0;
{ellenrzs, hogy mr szerepelt-e}
  while (b=false) and (y<c) do begin
   inc(y);
   if auto[y].rendszam=adat[x].rendszam then b:=true;
  end;
{ha nem szerepelt, hozzads}
  if b=false then begin
   inc(c);
   auto[c].rendszam:=adat[x].rendszam;
  end;
 end;
{kirs}
 writeln(c);
End;


procedure feladat5;
var y:integer;
    z:longint;
    maxora,maxperc,maxsec:byte;
    maxrendszam:string;

Begin
writeln('5. feladat');
{autk kivlogatsa, amik leglbb egyszer elhagytk a parkolt}
 for x:=1 to c do auto[x].ki:=false;
 for x:=1 to n do
  if adat[x].irany='Ki' then
   for y:=1 to c do
    if auto[y].rendszam=adat[x].rendszam then
     auto[y].ki:=true;
{mindegyik bejegyzs vgigmegy}
 for x:=1 to n do begin
{ha az irny BE, akkor a belps idpontjt eltrolja}
  if adat[x].irany='Be' then
   for y:=1 to c do
    if (auto[y].rendszam=adat[x].rendszam) and (auto[y].ki=true) then begin
     auto[y].orabe:=adat[x].orakulso;
     auto[y].percbe:=adat[x].perckulso;
     auto[y].secbe:=adat[x].seckulso;
    end;
{ha az irny KI, akkor a legutols belpstl szmtott idt hozzadja a
szmllhoz. Ha az aznapi els bejegyzs az autrl kilps, akkor jfltl
szmolja az idt.}
  if adat[x].irany='Ki' then
   for y:=1 to c do
    if (auto[y].rendszam=adat[x].rendszam) and (auto[y].ki=true) then begin
     z:=adat[x].orakulso*3600+adat[x].perckulso*60+adat[x].seckulso;
     z:=z-auto[y].orabe*3600-auto[y].percbe*60-auto[y].secbe;
     auto[y].ora:=auto[y].ora+(z div 3600);
     z:=(z mod 3600);
     auto[y].perc:=auto[y].perc+(z div 60);
     z:=(z mod 60);
     auto[y].sec:=auto[y].sec+z;
     auto[y].orabe:=0;
     auto[y].percbe:=0;
     auto[y].secbe:=0;
    end;
 end;
{a nap vgig a parkolban marad autknl a legutols kilps 23:59:59-ig
tart idszakot hozzadja a szmllhoz}
 for y:=1 to c do begin
  if (auto[y].orabe<>0) or (auto[y].percbe<>0) or (auto[y].secbe<>0) then begin
   z:=23*3600+59*60+59;
   z:=z-auto[y].orabe*3600-auto[y].percbe*60-auto[y].secbe;
   auto[y].ora:=auto[y].ora+(z div 3600);
   z:=(z mod 3600);
   auto[y].perc:=auto[y].perc+(z div 60);
   z:=(z mod 60);
   auto[y].sec:=auto[y].sec+z;
  end;
  auto[y].perc:=auto[y].perc+(auto[y].sec div 60);
  auto[y].sec:=(auto[y].sec mod 60);
  auto[y].ora:=auto[y].ora+(auto[y].perc div 60);
  auto[y].perc:=(auto[y].perc mod 60);
 end;
 maxora:=0;
 maxperc:=0;
 maxsec:=0;
{legtbb idt a parkolban tlt aut meghatrozsa}
 for y:=1 to c do
  if (maxora*3600+maxperc*60+maxsec)<(auto[y].ora*3600+auto[y].perc*60+auto[y].sec) then begin
   maxora:=auto[y].ora;
   maxperc:=auto[y].perc;
   maxsec:=auto[y].sec;
   maxrendszam:=auto[y].rendszam;
  end;
{kirs}
 writeln(maxrendszam,' ',maxora,' ra  ',maxperc,' perc  ',maxsec,' msodperc  ');
End;


procedure feladat6;
var y,ora:integer;
    z:longint;
    ki:text;

Begin
{fjl ltrehozsa}
 writeln('6. feladat');
 assign(ki,'parkolo.ki');
 {$I-}
 rewrite(ki);
 {$I+}
 if IOResult<>0 then begin
  writeln('Hiba a fjl ltrehozsnl!!!');
  halt;
 end;
 for y:=1 to c do begin
{a szmlls kezdete (8:00:00) belltsa}
  auto[y].orabe:=8;
  auto[y].percbe:=0;
  auto[y].secbe:=0;
 end;
 for x:=1 to n do begin
{ha az irny BE s a belps legkorbban 8 rakor van, akkor a belps
idpontjnak eltrolsa}
  if (adat[x].irany='Be') and (adat[x].orakulso>7) then
   for y:=1 to c do
    if auto[y].rendszam=adat[x].rendszam then begin
     auto[y].orabe:=adat[x].orakulso;
     auto[y].percbe:=adat[x].perckulso;
     auto[y].secbe:=adat[x].seckulso;
    end;
{ha az irny ki, s a kilps legksbb nyolckor van, akkor kirja h. nem kell
fizetni. Ha 8 utn is 18 ra eltt van, akkor a legutols belpstl (ha aznap
mg nem volt belps, akkor 8 rtl) hny rt kezdett meg a parkolban. Ha
17:59:59 utn volt, akkor kirja, hogy a legutols belpstl 17:59:59-ig hny
rt kezdett meg a parkolban.}
  if adat[x].irany='Ki' then
   if (adat[x].orakulso<8) or
   ((adat[x].orakulso=8) and (adat[x].perckulso=0) and (adat[x].seckulso=0))
   then writeln(ki,adat[x].rendszam,' nem kell fizetni')
   else
    for y:=1 to c do
     if auto[y].rendszam=adat[x].rendszam then begin
      if adat[x].orakulso<18 then begin
       z:=adat[x].orakulso*3600+adat[x].perckulso*60+adat[x].seckulso;
       z:=z-auto[y].orabe*3600-auto[y].percbe*60-auto[y].secbe;
       if (z mod 3600)=0 then ora:=(z div 3600)
       else ora:=(z div 3600)+1;
       writeln(ki,auto[y].rendszam,' ',ora,' ora utan kell fizetni');
      end
      else begin
       if auto[y].orabe>17 then writeln(ki,adat[x].rendszam,' nem kell fizetni')
       else begin
        z:=17*3600+59*60+59;
        z:=z-auto[y].orabe*3600-auto[y].percbe*60-auto[y].secbe;
        if (z mod 3600)=0 then ora:=(z div 3600)
        else ora:=(z div 3600)+1;
        writeln(ki,auto[y].rendszam,' ',ora,' ora utan kell fizetni');
       end;
      end;
     end;
 end;
 close(ki);
 writeln('Adatok kirva a kimeneti fjlba.');
End;





BEGIN
clrscr;
feladat1;
feladat2;
feladat3;
feladat4;
feladat5;
feladat6;
END.



