diff --git "a/\355\225\234\352\260\200\354\235\200/10866.py" "b/\355\225\234\352\260\200\354\235\200/10866.py" new file mode 100644 index 0000000..10d9e95 --- /dev/null +++ "b/\355\225\234\352\260\200\354\235\200/10866.py" @@ -0,0 +1,24 @@ +from collections import deque +import sys + +n = int(input()) +answer = deque() +for _ in range(n): + a = list(sys.stdin.readline().split()) + + if a[0] == 'push_front': + answer.appendleft(a[1]) + elif a[0] == 'push_back': + answer.append(a[1]) + elif a[0] == 'pop_front': + print(answer.popleft() if answer else -1) + elif a[0] == 'pop_back': + print(answer.pop() if answer else -1) + elif a[0] == 'size': + print(len(answer)) + elif a[0] == 'empty': + print(0 if answer else 1) + elif a[0] == 'front': + print(answer[0] if answer else -1) + else : # a == 'back' + print(answer[-1] if answer else -1) \ No newline at end of file diff --git "a/\355\225\234\352\260\200\354\235\200/15649.py" "b/\355\225\234\352\260\200\354\235\200/15649.py" new file mode 100644 index 0000000..9f8c30b --- /dev/null +++ "b/\355\225\234\352\260\200\354\235\200/15649.py" @@ -0,0 +1,18 @@ +def back_tracking(arr, len, used_num): + if len == m: + print(*arr) + return + + for i in range(1, n+1): + if not used_num[i]: + arr.append(i) + used_num[i] = True + back_tracking(arr, len + 1, used_num) + arr.pop() + used_num[i] = False + +n, m = list(map(int, input().split())) + +nums = [i+1 for i in range(n + 1)] +used_num = [False] * (n+1) +back_tracking([], 0, used_num) diff --git "a/\355\225\234\352\260\200\354\235\200/15650.py" "b/\355\225\234\352\260\200\354\235\200/15650.py" new file mode 100644 index 0000000..727dfc8 --- /dev/null +++ "b/\355\225\234\352\260\200\354\235\200/15650.py" @@ -0,0 +1,14 @@ +def backtracking (arr, start): + if m == len(arr): + print(*arr) + return + + for i in range(start, n+1): + arr.append(i) + backtracking(arr, i+1) + arr.pop() + + +n, m = list(map(int, input().split())) +s = 1 +backtracking([], s) \ No newline at end of file diff --git "a/\355\225\234\352\260\200\354\235\200/4949.py" "b/\355\225\234\352\260\200\354\235\200/4949.py" new file mode 100644 index 0000000..d937eed --- /dev/null +++ "b/\355\225\234\352\260\200\354\235\200/4949.py" @@ -0,0 +1,28 @@ +import sys + +while True: + state = True + stack = [] + commands = list(sys.stdin.readline().rstrip()) + if commands == ['.']: # command는 list이기 때문에 []리스트로 일치 판별 + break + for char in commands: + if char == '(': + stack.append('(') + elif char == '[': + stack.append('[') + elif char == ')': + if stack and stack.pop() == '(': + state = True + else: + state = False + break + elif char == ']': + if stack and stack.pop() == '[': + state = True + else : + state = False + break + if stack: + state = False #stack이 비었을 때만 yes + print('yes' if state else 'no') \ No newline at end of file diff --git "a/\355\225\234\352\260\200\354\235\200/B10828.py" "b/\355\225\234\352\260\200\354\235\200/B10828.py" new file mode 100644 index 0000000..2e42fc0 --- /dev/null +++ "b/\355\225\234\352\260\200\354\235\200/B10828.py" @@ -0,0 +1,23 @@ +import sys + +stack = [] +n = int(sys.stdin.readline()) +for _ in range(n): + command = list(sys.stdin.readline().split()) + if command[0] == "push" : + stack.append(command[1]) + + elif command[0] == "pop" : + if(stack) : print(stack.pop()) + else : print(-1) + + elif command[0] == "size": + print(len(stack)) + + elif command[0] == "empty": + if(stack): print(0) + else : print(1) + + else : + if(stack) : print(stack[-1]) + else : print(-1) diff --git "a/\355\225\234\352\260\200\354\235\200/B10845.py" "b/\355\225\234\352\260\200\354\235\200/B10845.py" new file mode 100644 index 0000000..b9dfc7c --- /dev/null +++ "b/\355\225\234\352\260\200\354\235\200/B10845.py" @@ -0,0 +1,18 @@ +import sys + +queue = [] +n = int(sys.stdin.readline()) +for _ in range(n): + command = list(sys.stdin.readline().split()) + if command[0] == "push": + queue.append(command[1]) + elif command[0] == "pop": + print(queue.pop(0) if queue else -1) + elif command[0] == "size": + print(len(queue)) + elif command[0] == "empty": + print(0 if queue else 1) + elif command[0] == "front": + print(queue[0] if queue else -1) + else: #back + print(queue[-1] if queue else -1) \ No newline at end of file