ALGORITHM/PYTHON

백준 BAEKJOON 28295번 체육은 코딩과목 입니다 [PYTHON/파이썬]

칼코
반응형

 

 

 

 

 

백준 BAEKJOON 28295번 체육은 코딩과목 입니다 [PYTHON/파이썬]


<문제 출처> (BRONZE Ⅳ)

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

 

28295번: 체육은 코딩과목 입니다

$10$개의 지시를 모두 이행한 후 학생들이 바라보는 방향을 나타내는 문자를 출력한다. 학생들이 바라보는 방향이 북쪽이라면 N, 동쪽이라면 E, 서쪽이라면 W, 남쪽이라면 S를 출력한다.

www.acmicpc.net

 

 

 

 

 

<풀이>

리스트에 '북', '동', '남', '서' 순서대로 담았다.

초기 방향이 북쪽이니 입력된 1,2,3에 맞춰서 방향을 바꾸어서 풀었다.

 

 

 

 

 

 

<코드>

direction = ["N", "E", "S", "W"]
result = "N"

for i in range(10):
    command = int(input())
    if command == 1:
        result = direction[(direction.index(result) + 1) % 4]
    elif command == 2:
        result = direction[(direction.index(result) + 2) % 4]
    elif command == 3:
        result = direction[(direction.index(result) + 3) % 4]

print(result)

 

 

 

 

 

 

반응형