less than 1 minute read

백준링크

자료구조 스택 활용하기

파이썬

import sys
input = sys.stdin.readline

cnt=1
temp = True
s = []
a = []

n = int(input())

for i in range (n):
    num = int(input())
    while cnt <= num:
        s.append(cnt)
        a.append('+')
        cnt+=1
    
    if s[-1] == num:
        s.pop()
        a.append('-')
    else:
        temp=False
        break

if temp == False:
    print("NO")
else:
    for i in a:
        print(i)

카테고리:

업데이트:

댓글남기기