Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 10430
- 새싹
- 사파리 월드
- 백준1476
- 백준
- 개수 세기
- 10926
- safari world
- 디버그심볼
- 18108
- 기본메신저
- 10807
- BitMasking
- 1330
- dp
- 꼬마 정민
- PreferenceManager
- 백준3085
- Android
- debugSymbolLevel
- 백준1107
- 파이썬
- 2525
- kotlin
- Class Delegation
- 코틀린
- Counting The number
- 25083
- baekjoon
- 브루트포스
Archives
- Today
- Total
세상을 더 좋게
[백준] 1874 '스택 수열' 파이썬(python) 본문
https://www.acmicpc.net/problem/1874
1874번: 스택 수열
1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다.
www.acmicpc.net
n = int(input())
stack = [] //실제 주어지는 리스트를 스택으로 저장하는 리스트
result = [] //결과를 출력할 리스트
count = 1 // 숫자를 차례대로 넣는다는 문제에서 1부터 시작.
temp = True
for i in range(n):
num = int(input())
while count <= num:
stack.append(count)
result.append('+')
count += 1
if s[-1] == num:
stack.pop()
result.append('-')
else:
temp = False
if temp == False:
print('NO')
else:
for i in result:
print(i)
스택의 기본 구조를 알려주는 문제.
문제의 설명이 친절하지는 못하여 해석하는 것에 시간은 걸리지만 해석을 한 뒤에는 append와 pop을 활용하여 쉽게 작성할 수 있다.