링크 - https://www.acmicpc.net/problem/2346
from collections import deque
import sys
input = sys.stdin.readline
#원형큐
n = int(input())
#정답에 인덱스를 넣어야 하기 때문에 enumerate사용
balloon = deque(enumerate(map(int,input().split())))
answer = []
while balloon:
idx, val = balloon.popleft()
answer.append(idx+1)
if val>0:
balloon.rotate(-(val-1))
else:
balloon.rotate(-val)
for a in answer:
print(a, end=" ")
문제를 읽으면서 원형큐를 사용해야 한다고 생각을 했고 저번에 배웠던 deque.rotate()를 쓰면 되겠다고 생각을 했다.
인덱스 실수를 몇 번 해주면서 고쳐주면 된다~ㅎ
링크 - https://www.acmicpc.net/problem/4949
import sys
input = sys.stdin.readline
while True:
flag = True
line = input().rstrip()
stack=[]
#종료조건
if line==".":
break
for l in line:
if l=="("or l=="[":
stack.append(l)
elif l==")":
if stack and stack[-1]=="(":
stack.pop()
else:
flag = False
break
elif l=="]":
if stack and stack[-1]=="[":
stack.pop()
else:
flag = False
break
if len(stack)!=0 or flag==False:
print('no')
else:
print('yes')
괄호 확인 문제였다. 두 종류의 괄호만 체크하면 돼서 비교적 수월했다.