Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

noisia7 avatar noisia7 0 Точки

3. Football Cards

Здравейте , имам проблем с тази задача ,

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.

Input

The input (the cards) will come on a single line separated by a single space.

Работи вярно и тестовете си минават но ми дава  80/100 в judge 

https://pastebin.com/10QgZYA1

 

Тагове:
0
Python Fundamentals
niyazihasan avatar niyazihasan 83 Точки

Здравей, поправих кода ти :)

cards = input().split()
set_1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
set_2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
 
team_a_counter = 11
team_b_counter = 11
 
for card in cards:
    tokens = card.split("-")
    team = tokens[0]
    number = int(tokens[1])
 
    if team == "A":
        if number in set_1:
            set_1.remove(number)
            team_a_counter -= 1
    else:
        if number in set_2:
            set_2.remove(number)
            team_b_counter -= 1
 
print(f"Team A - {team_a_counter}; Team B - {team_b_counter}")
if team_b_counter < 7 or team_a_counter < 7:
    print(f"Game was terminated")

0
noisia7 avatar noisia7 0 Точки

Мерси много :)))

Дава 100/100 , но при подаване на вход от сорта на : " А-1 А-2 А-3 А-4 А-5 А-6 А-7 А-8 "

намаля играчите до под 7 и никога не спира. В случая ползваш ако са < 7 само да принтиращ но не спираш играта , явно и джъдж не го оценява както трябва .

 

0
06/06/2020 12:17:33
D.V.Ivanov avatar D.V.Ivanov 6 Точки

Така също ще даде 80/100. Трябва да прекъснете цикъла с условието за броя на играчите.

info = input()
list = info.split()
list_team_A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
list_team_B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

for el in list:
    element = el.split("-")
    team = element[0]
    player = int(element[1])
    if team == "A":
        if player in list_team_A:
            list_team_A.remove(player)
    elif team == "B":
        if player in list_team_B:
            list_team_B.remove(player)
    if len(list_team_A) < 7 or len(list_team_B) < 7:
        break

print(f"Team A - {len(list_team_A)}; Team B - {len(list_team_B)}")

if len(list_team_A) < 7 or len(list_team_B) < 7:
    print("Game was terminated")
0
Julianh12 avatar Julianh12 3 Точки

Ето и трети вариант на задачата:

string_players=input().split(" ")
list_one=[]
for i in string_players:
    list_one.append(i)
team_one=11
team_two=11
terminated=False
new_list=list(set(list_one))
for i in range(1,11+1):
    team_one-=int(new_list.count(f"A-{i}"))
    team_two-=int(new_list.count(f"B-{i}"))
    if team_one <7 or team_two<7:
        print(f"Team A - {team_one}; Team B - {team_two}")
        print("Game was terminated")
        terminated=True
        break
if terminated!=True:
    print(f"Team A - {team_one}; Team B - {team_two}")

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.