-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 1874 : 스택 수열 | ||
|
||
n = int(input()) # 수열의 크기 | ||
sequence = [int(input()) for _ in range(n)] # 주어진 수열 | ||
|
||
stack = [] | ||
result = [] | ||
current = 1 # 스택에 넣을 숫자 | ||
possible = True | ||
|
||
for num in sequence: | ||
# 현재 숫자보다 수열에서 필요한 숫자가 크거나 같을 때까지 push | ||
while current <= num: | ||
stack.append(current) | ||
result.append('+') | ||
current += 1 | ||
|
||
# 스택의 최상단이 num과 같다면 pop | ||
if stack and stack[-1] == num: | ||
stack.pop() | ||
result.append('-') | ||
else: | ||
possible = False | ||
break | ||
|
||
if possible: | ||
print("\n".join(result)) | ||
else: | ||
print("NO") |