Advertisement
Void-voiD

Untitled

Apr 2nd, 2023
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | Source Code | 0 0
  1. def f(k):
  2.     return -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.         mx = score
  16.  
  17.     found = False
  18.     for y in schools:
  19.         if y[0] == school:
  20.             found = True
  21.             if y[1] == mx == score:
  22.                 y[2] += 1
  23.             elif score == mx and mx > y[1]:
  24.                 y[2] = 1
  25.         if y[1] < mx:
  26.             y[2] = 0
  27.     if not found:
  28.         amount = 0
  29.         if score == mx:
  30.             amount = 1
  31.         schools.append([school, score, amount])
  32.  
  33. a.close()
  34. a = open('output.txt', 'w')
  35. first_print = True
  36. schools.sort(key=f)
  37. mx_count = schools[0][2]
  38.  
  39. i = 0
  40. while schools[i][1] == mx and schools[i][2] == mx_count:
  41.     if first_print:
  42.         print(schools[i][0], end='', file=a)
  43.         first_print = False
  44.     else:
  45.         print('\n' + str(schools[i][0]), end='', file=a)
  46.     i += 1
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement