diff --git a/zeta_python/1874.py b/zeta_python/1874.py deleted file mode 100644 index 4efe6c4..0000000 --- a/zeta_python/1874.py +++ /dev/null @@ -1,94 +0,0 @@ -""" -1874: 스택 수열 -문제: - 스택 (stack)은 기본적인 자료구조 중 하나로, 컴퓨터 프로그램을 작성할 때 자주 이용되는 개념이다. - 스택은 자료를 넣는 (push) 입구와 자료를 뽑는 (pop) 입구가 같아 제일 나중에 들어간 자료가 제일 먼저 나오는 (LIFO, Last in First out) 특성을 가지고 있다. - - 1부터 n까지의 수를 스택에 넣었다가 뽑아 늘어놓음으로써, 하나의 수열을 만들 수 있다. - 이때, 스택에 push하는 순서는 반드시 오름차순을 지키도록 한다고 하자. - 임의의 수열이 주어졌을 때 스택을 이용해 그 수열을 만들 수 있는지 없는지, 있다면 어떤 순서로 push와 pop 연산을 수행해야 하는지를 알아낼 수 있다. - 이를 계산하는 프로그램을 작성하라. -입력: - 첫 줄에 n (1 ≤ n ≤ 100,000)이 주어진다. - 둘째 줄부터 n개의 줄에는 수열을 이루는 1이상 n이하의 정수가 하나씩 순서대로 주어진다. 물론 같은 정수가 두 번 나오는 일은 없다. - -출력: - 입력된 수열을 만들기 위해 필요한 연산을 한 줄에 한 개씩 출력한다. - push연산은 +로, pop 연산은 -로 표현하도록 한다. 불가능한 경우 NO를 출력한다. -""" -""" -TC1: -``` -Input: -8 -4 -3 -6 -8 -7 -5 -2 -1 -Output: -+ -+ -+ -+ -- -- -+ -+ -- -+ -+ -- -- -- -- -- -``` -TC2: -``` -Input: -5 -1 -2 -5 -3 -4 -Output: -NO -``` -""" -n = int(input()) -que = list(range(n,0,-1)) - -stack = list() - -def pop(): - global stack - global que - - poped = stack.pop() - que.insert(0,poped) - -def push(): - global stack - global que - - pushed = que.pop() - stack.append(pushed) - - -while True: - a = input() - if a == 'push': - push() - elif a == 'pop': - pop() - elif a == 'que': - print(que) - elif a == 'stack': - print(stack) - else: - continue diff --git a/zeta_python/completed/10773.py b/zeta_python/completed/10773.py new file mode 100644 index 0000000..ce8e412 --- /dev/null +++ b/zeta_python/completed/10773.py @@ -0,0 +1,13 @@ +def solve(K, I): + stack = list() + for i in I: + if i: + stack.append(i) + else: + stack.pop() + return sum(stack) + + +if __name__ == '__main__': + K = int(input()) + print(solve(K, [int(input()) for _ in range(K)])) diff --git a/zeta_python/completed/1874.py b/zeta_python/completed/1874.py new file mode 100644 index 0000000..6aa3606 --- /dev/null +++ b/zeta_python/completed/1874.py @@ -0,0 +1,22 @@ +def solve(N, I): + ret = [] + stack = [] + c = 0 + for i, x in enumerate(I): + while c < x: + c += 1 + stack.append(c) + ret.append("+") + + if stack[-1] == x: + stack.pop() + ret.append("-") + + else: + return "NO" + return "\n".join(ret) + + +if __name__ == '__main__': + N = int(input()) + print(solve(N, list(int(input()) for _ in range(N))))