기록하고 까먹지 말기

10866 본문

전공/백준

10866

yha97 2022. 12. 19. 10:25

날짜 : 2022. 12. 19

사용 언어 : python

 

문제

 

 

코드

import sys

n = int(sys.stdin.readline())
d = list()

for _ in range(n):
    temp = str(sys.stdin.readline().rstrip())
    if temp[:3] == "pus":
        a, b = temp.split()
        b = int(b)
        if a == "push_front":
            d.insert(0, b)
        elif a == "push_back":
            d.append(b)
    else:
        if temp == "front":
            if len(d) == 0: print(-1)
            else: print(d[0])
        elif temp == "back":
            if len(d) == 0: print(-1)
            else: print(d[-1])
        elif temp == "size":
            print(len(d))
        elif temp == "empty":
            if len(d): print(0)
            else: print(1)
        elif temp == "pop_front":
            if len(d) == 0: print(-1)
            else:
                print(d[0])
                del d[0]
        elif temp == "pop_back":
            if len(d) == 0: print(-1)
            else:
                print(d[-1])
                del d[-1]

 

풀이

- 조건에 맞게 deque 를 구현하는 문제였다.

 

 

알게된 점

- split() 하는 지점을 약간 헷갈리는 바람에 시간을 허비했다.

 

 

참고 사이트

 

'전공 > 백준' 카테고리의 다른 글

11723  (0) 2022.12.20
18111  (0) 2022.12.19
1259  (0) 2022.12.19
2559  (0) 2022.12.19
17425  (0) 2022.12.14