티스토리 뷰

C, C++/Baekjoon Online Judge

Baekjoon 백준 1547번 공

j0n9m1n1 j0n9m1n1 2019. 8. 6. 23:46

Python3.x

1.비루하다

N = int(input())
ball = [1, 0, 0]
for i in range(N):
   x, y = map(int, input().split())
   if ball[y - 1] == 1:
      ball[y - 1] = 0
      ball[x - 1] = 1
   elif ball[x - 1] == 1:
      ball[x - 1] = 0
      ball[y - 1] = 1
print(ball.index(1) + 1)

2. skyisclear분 참고 함

N = int(input())
ball = [0, 1, 0, 0]
for i in range(N):
   x, y = map(int, input().split())
   ball[x], ball[y] = ball[y], ball[x]
print(ball.index(1))

https://www.acmicpc.net/problem/1547