[백준/파이썬] 14038번 풀이

업데이트:



문제 정보


풀이

문제

Each player in a tournament plays six games. There are no ties. The tournament director places the players in groups based on the results of games as follows:

  • if a player wins 5 or 6 games, they are placed in Group 1;

  • if a player wins 3 or 4 games, they are placed in Group 2;

  • if a player wins 1 or 2 games, they are placed in Group 3;

  • if a player does not win any games, they are eliminated from the tournament.

Write a program to determine which group a player is placed in

입력 요약
The input consists of six lines, each with one of two possible letters: W (to indicate a win) or L (to indicate a loss).

출력 요약
The output will be either 1, 2, 3 (to indicate which Group the player should be placed in) or -1 (to indicate the player has been eliminated).

코드

w = 0
for _ in range(6):
    if input()=='W': w += 1

if w > 4: print(1)
elif w > 2: print(2)
elif w > 0: print(3)
else: print(-1)

설명

핵심은 구현 관점에서 Each player in a tournament plays six games. There are no ties. The tournament director places the players in groups based on the results of games as …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기