FANDOM


def f(x):
    print(x, '. feladat', sep="")

def mpbe(x): # type(x) : list
    return x[0]*3600 + x[1]*60 + x[2]

def mpbol(x):
    ora = x//3600
    perc = (x-ora*3600)//60
    mp = x-ora*3600-perc*60
    return [ora, perc, mp]

#1. feladat
forras = open('forgalom.txt')
jarmuvek_sz = forras.readline().strip()
adatok = []
athaladas = []
for sor in forras:
    athaladas = list(map(lambda x: int(x), sor.strip().split()[:-1]))
    athaladas.append(sor.strip().split()[-1])
    adatok.append(athaladas)
    athaladas = []
forras.close()

f(2)
sorszam = int(input('adja meg a jarmu sorszamat: '))
print('a jarmu', adatok[sorszam-1][-1], 'varos iranyaba haladt')

f(3)
mp_kulonbseg = mpbe(adatok[-1][:3]) - mpbe(adatok[-2][:3])
print(mp_kulonbseg, 'masodperc volt a 2 utolso auto kozt')

f(4)
orak = [] #ora, db, 'A' varos, 'F' varos
db = 0
a_varos = 0
f_varos = 0
for i in range(1, adatok[-1][0]+1):
    for elem in adatok:
        if i == elem[0]:
            db +=1
            if elem[-1] == 'A':
                a_varos += 1
            else:
                f_varos += 1
    orak.append([i, db, a_varos, f_varos])
    db, a_varos, f_varos = 0, 0, 0
for elem in orak:
    if elem[1] != 0:
        print('ora:', elem[0], 'A:', elem[2], 'F:', elem[3])

f(5)
sebessegek = set()
for elem in adatok:
    sebessegek.add(elem[3])
top10_sebessegek_lista = sorted(list(sebessegek))[:10]
for elem in top10_sebessegek_lista:
    for elem2 in adatok:
        if elem == elem2[3]:
            print(elem2[0], elem2[1], elem2[2], elem2[4], round(1000/elem2[3], 1), 'm/s')
            break
#6. feladat
ki = []
for elem in adatok:
    if elem[-1] == 'A':
       ki.append(mpbe(elem[:3])+elem[3])

for i in range(len(ki)-1):
    if ki[i] > ki[i+1]:
        ki[i+1] = ki[i]
    
kimenet = open('also.txt', 'w')
for elem in ki:
    print(' '.join(list(map(lambda x: str(x), mpbol(elem)))), file=kimenet)
kimenet.close()