Skip to content

Instantly share code, notes, and snippets.

@andriiburka
Created February 3, 2020 16:24
Show Gist options
  • Save andriiburka/00f42ff654239830b0370486612fba4b to your computer and use it in GitHub Desktop.
Save andriiburka/00f42ff654239830b0370486612fba4b to your computer and use it in GitHub Desktop.
'''
The rules:
Two teams, named "A" and "B" have 11 players each.
The players on each team are numbered from 1 to 11.
Any player may be sent off the field by being given a red card.
If one of the teams has less than 7 players remaining, the game is stopped immediately by the referee,
and the team with less than 7 players loses.
A card is a string with the team's letter ('A' or 'B') followed by a single dash and player's number.
e.g. the card 'B-7' means player #7 from team B received a card. (index 6 of the list)
The task: Given a list of cards (could be empty),
return the number of remaining players on each team at the end of the game in the format:
"Team A - {players_count}; Team B - {players_count}".
If the game was terminated print an additional line: "Game was terminated"
Note for the random tests: If a player that has already been sent off receives another card - ignore it.
'''
str_in = map(str, input().split())
players = 11
team_a = []
a_counter = players
team_b = []
b_counter = players
for player in range(1, players + 1):
team_a.append(str(player))
team_b.append(str(player))
for el in str_in:
if el[0] == 'A':
a_counter -= 1
a_remover = el.replace('A-', '')
if a_remover in team_a:
team_a.remove(a_remover)
elif el[0] == 'B':
b_counter -= 1
b_remover = el.replace('B-', '')
if b_remover in team_b:
team_b.remove(b_remover)
print(f'Team A - {a_counter}; Team B - {b_counter}', )
if a_counter < 7 or b_counter < 7:
print('Game was terminated')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment