Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 03. Football League , Exam Preparation l 100/100 REGEX .
- # https://judge.softuni.org/Contests/Practice/Index/967#2
- def adding_results(team):
- goals = team[2].split(":")
- team1 = team[0]
- team2 = team[1]
- goals1 = int(goals[0])
- goals2 = int(goals[1])
- if team1 not in top_3_goals:
- top_3_goals[team1] = goals1
- else:
- top_3_goals[team1] += goals1
- if team2 not in top_3_goals:
- top_3_goals[team2] = goals2
- else:
- top_3_goals[team2] += goals2
- if goals1 == 0 and goals2 == 0 or goals1 == goals2: # for Draw 0:0
- if team1 not in league_standings:
- league_standings[team1] = 0
- league_standings[team1] += 1
- else:
- league_standings[team1] += 1
- if team2 not in league_standings:
- league_standings[team2] = 0
- league_standings[team2] += 1
- else:
- league_standings[team2] += 1
- elif goals1 > goals2: # TEAM 1 WON
- if team1 not in league_standings:
- league_standings[team1] = 0
- league_standings[team1] += 3
- else:
- league_standings[team1] += 3
- if team2 not in league_standings:
- league_standings[team2] = 0
- elif goals1 < goals2: # TEAM 2 WON
- if team2 not in league_standings:
- league_standings[team2] = 0
- league_standings[team2] += 3
- else:
- league_standings[team2] += 3
- if team1 not in league_standings:
- league_standings[team1] = 0
- import re
- top_3_goals = {}
- league_standings = {}
- key_pass = input()
- data = input()
- new_key_pass = ""
- for char in key_pass:
- if not char.isalnum():
- new_key_pass += "\ " + char
- else:
- new_key_pass += char
- new_key_pass = new_key_pass.replace(" ", "")
- pattern_teams = fr'({new_key_pass})([a-zA-Z0-9]+)\1'
- teams = []
- while not data == 'final':
- matched_teams = re.findall(pattern_teams, data)
- for index, el in enumerate(matched_teams):
- reverse_name = el[1]
- teams.append(reverse_name[::-1].upper())
- current_score = data.split(' ')[-1]
- teams.append(current_score)
- if len(teams) < 3:
- teams.insert(0, "")
- adding_results(teams)
- teams.clear()
- data = input()
- details = []
- print('League standings:')
- team_counter1 = 0
- for team in sorted(league_standings.items(), key=lambda kv: (-kv[1], kv[0])):
- team_counter1 += 1
- print(f'{team_counter1}. {team[0]} {team[1]}')
- print('Top 3 scored goals:')
- team_counter2 = 0
- for el in sorted(top_3_goals.items(), key=lambda x: (-x[1], x[0])):
- team_counter2 += 1
- print(f'- {el[0]} -> {el[1]}')
- if team_counter2 == 3:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement