Advertisement
Void-voiD

Untitled

Apr 3rd, 2023
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | Source Code | 0 0
  1. def f(k):
  2.     return -k[1], -k[2], k[0]
  3.  
  4.  
  5. a = open('input.txt', 'r', encoding='utf-8')
  6. mx = 0
  7. schools = []  # [номер школы, максимальный балл школы, количество учеников школы, у которых максимальный балл среди всех учеников всех школ]
  8.  
  9. for x in a.readlines():
  10.     fn, ln, school, score = x.split()
  11.     school = int(school)
  12.     score = int(score)
  13.  
  14.     if score == mx:
  15.         found = False
  16.         for sch in schools:
  17.             if sch[0] == school:
  18.                 sch[2] += 1
  19.         if not found:
  20.             schools.append([school, score, 1])
  21.     if score > mx:
  22.         found = False
  23.         for sch in schools:
  24.             if sch[0] == school:
  25.                 sch[2] = 1
  26.             else:
  27.                 sch[2] = 0
  28.         if not found:
  29.             schools.append([school, score, 1])
  30.  
  31.     if score > mx:
  32.         mx = score
  33.  
  34. a.close()
  35. a = open('output.txt', 'w')
  36. first_print = True
  37. schools.sort(key=f)
  38. mx_count = schools[0][2]
  39.  
  40. i = 0
  41. while schools[i][1] == mx and schools[i][2] == mx_count:
  42.     if first_print:
  43.         print(schools[i][0], end='', file=a)
  44.         first_print = False
  45.     else:
  46.         print('\n' + str(schools[i][0]), end='', file=a)
  47.     i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement