Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def f(k):
- return -k[2], k[0]
- a = open('input.txt', 'r', encoding='utf-8')
- mx = 0
- schools = [] # [номер школы, максимальный балл школы, количество учеников школы, у которых максимальный балл среди всех учеников всех школ]
- for x in a.readlines():
- fn, ln, school, score = x.split()
- school = int(school)
- score = int(score)
- if score > mx:
- mx = score
- found = False
- for y in schools:
- if y[0] == school:
- found = True
- if y[1] == mx == score:
- y[2] += 1
- elif score == mx and mx > y[1]:
- y[2] = 1
- if y[1] < mx:
- y[2] = 0
- if not found:
- amount = 0
- if score == mx:
- amount = 1
- schools.append([school, score, amount])
- a.close()
- a = open('output.txt', 'w')
- first_print = True
- schools.sort(key=f)
- mx_count = schools[0][2]
- i = 0
- while schools[i][1] == mx and schools[i][2] == mx_count:
- if first_print:
- print(schools[i][0], end='', file=a)
- first_print = False
- else:
- print('\n' + str(schools[i][0]), end='', file=a)
- i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement