From 752a31efd54ec0ee6c969b7a78cef9f685fbb94a Mon Sep 17 00:00:00 2001 From: haesol1013 Date: Sun, 8 Sep 2024 23:14:24 +0900 Subject: [PATCH] s2_1874.py --- .../s2_1874.py" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "\354\213\240\355\225\264\354\206\224/s2_1874.py" diff --git "a/\354\213\240\355\225\264\354\206\224/s2_1874.py" "b/\354\213\240\355\225\264\354\206\224/s2_1874.py" new file mode 100644 index 00000000..d8ef6e6c --- /dev/null +++ "b/\354\213\240\355\225\264\354\206\224/s2_1874.py" @@ -0,0 +1,41 @@ +# 스택 수열 - 1874 + +import sys +input = lambda: sys.stdin.readline().rstrip() + + +def stack(target: list[int]) -> str | list[str]: + seq: list[int] = list(range(len(target), 0, -1)) + save: list[int] = [] + result: list[str] = [] + + for i in target: + while True: + if save and save[-1] == i: + save.pop() + result.append("-") + break + + if not seq: + return "NO" + + save.append(seq.pop()) + result.append("+") + + return result + + +def main(): + n = int(input()) + target = [int(input()) for _ in range(n)] + result = stack(target) + + if type(result) is list: + for i in result: + print(i) + else: + print(result) + + +if __name__ == "__main__": + main()