Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- PYTHON
- 데이콘
- programmers
- 캐치카페
- 코로나19
- 자연어처리
- 백준
- SW Expert Academy
- 프로그래머스
- gs25
- dacon
- Baekjoon
- leetcode
- 맥북
- 편스토랑 우승상품
- 프로그래머스 파이썬
- 우분투
- Git
- hackerrank
- 금융문자분석경진대회
- Real or Not? NLP with Disaster Tweets
- 편스토랑
- ubuntu
- Docker
- github
- 더현대서울 맛집
- AI 경진대회
- Kaggle
- 파이썬
- ChatGPT
Archives
- Today
- Total
솜씨좋은장씨
[BaekJoon] 10866번 : 덱 (Python) 본문
728x90
반응형
1일 1문제 81일차!
오늘의 문제는 백준의 덱 (Deque) 입니다.
Solution
my_dequeue = []
command_list = []
num = input()
for i in range(int(num)):
command = input()
command_list.append(command)
for command in command_list:
cmd = command.split()
if cmd[0] == 'push_back':
my_dequeue.append(cmd[1])
elif cmd[0] == 'push_front':
my_dequeue.insert(0, cmd[1])
elif cmd[0] == 'pop_front':
if len(my_dequeue) != 0:
print(my_dequeue.pop(0))
else:
print(-1)
elif cmd[0] == 'pop_back':
if len(my_dequeue) != 0:
print(my_dequeue.pop(-1))
else:
print(-1)
elif cmd[0] == 'back':
if len(my_dequeue) != 0:
print(my_dequeue[-1])
else:
print(-1)
elif cmd[0] == 'front':
if len(my_dequeue) != 0:
print(my_dequeue[0])
else:
print(-1)
elif cmd[0] == 'size':
print(len(my_dequeue))
elif cmd[0] == 'empty':
if len(my_dequeue) != 0:
print(0)
else:
print(1)
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[HackerRank] Day of Programmer (Python) (0) | 2020.04.29 |
---|---|
[HackerRank] Grading Students (Python) (0) | 2020.04.28 |
[BaekJoon] 1158번 : 요세푸스 문제 (Python) (0) | 2020.04.26 |
[BaekJoon] 1463번 : 1로 만들기 (Python) (0) | 2020.04.25 |
[BaekJoon] 11722번 : 가장 긴 감소하는 부분 수열 (Python) (0) | 2020.04.24 |
Comments