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

업데이트:



문제 정보


풀이

문제

To pass the time, Bessie the cow and her friend Elsie like to play a version of a game they saw at the county fair.

To start, Bessie puts three inverted shells on a table and places a small round pebble under one of them (at least she hopes it is a pebble – she found it on the ground in one of the pastures). …

입력 요약
The first line of the input file contains an integer $N$ giving the number of swaps ($1 \leq N \leq 100$). Each of the next $N$ lines describes a step of the game and contains three integers $a$, $b$, and $g$, indicating that shells $a$ and $b$ were swapped by Bessie, and then El …

출력 요약
Please output the maximum number of points Elsie could have earned.

코드

l=[0,1,2,3]
d={1:0,2:0,3:0}
for n in range(int(input())):
    a,b,g=map(int,input().split())
    l[a],l[b]=l[b],l[a]
    d[l[g]]+=1
print(max(d.values()))

설명

핵심은 구현 관점에서 To pass the time, Bessie the cow and her friend Elsie like to play a version of a game they saw at the county fair. …를 만족하도록 로직을 구성하는 것입니다.

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

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



댓글남기기