Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def f(k):
- return -k[1], -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:
- found = False
- for sch in schools:
- if sch[0] == school:
- sch[2] += 1
- if not found:
- schools.append([school, score, 1])
- if score > mx:
- found = False
- for sch in schools:
- if sch[0] == school:
- sch[2] = 1
- else:
- sch[2] = 0
- if not found:
- schools.append([school, score, 1])
- if score > mx:
- mx = score
- 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