diff --git a/zeta_python/completed/10845.py b/zeta_python/completed/10845.py new file mode 100644 index 0000000..6bb2a30 --- /dev/null +++ b/zeta_python/completed/10845.py @@ -0,0 +1,36 @@ +import sys +from collections import deque + +queue = deque() + + +def dispatch(command: str, *args): + if command == "push": + queue.append(int(args[0])) + elif command == "pop": + if queue: + return queue.popleft() + else: + return -1 + elif command == "size": + return len(queue) + elif command == "empty": + return 0 if queue else 1 + elif command == "front": + if queue: + return queue[0] + else: + return -1 + elif command == "back": + if queue: + return queue[-1] + else: + return -1 + + +if __name__ == "__main__": + N = int(sys.stdin.readline()) + for _ in range(N): + d = dispatch(*sys.stdin.readline().strip().split()) + if d is not None: + print(d) diff --git a/zeta_python/completed/18258.py b/zeta_python/completed/18258.py new file mode 100644 index 0000000..6bb2a30 --- /dev/null +++ b/zeta_python/completed/18258.py @@ -0,0 +1,36 @@ +import sys +from collections import deque + +queue = deque() + + +def dispatch(command: str, *args): + if command == "push": + queue.append(int(args[0])) + elif command == "pop": + if queue: + return queue.popleft() + else: + return -1 + elif command == "size": + return len(queue) + elif command == "empty": + return 0 if queue else 1 + elif command == "front": + if queue: + return queue[0] + else: + return -1 + elif command == "back": + if queue: + return queue[-1] + else: + return -1 + + +if __name__ == "__main__": + N = int(sys.stdin.readline()) + for _ in range(N): + d = dispatch(*sys.stdin.readline().strip().split()) + if d is not None: + print(d) diff --git a/zeta_python/completed/2161.py b/zeta_python/completed/2161.py new file mode 100644 index 0000000..15de788 --- /dev/null +++ b/zeta_python/completed/2161.py @@ -0,0 +1,21 @@ +from collections import deque + + +def solve(N): + queue = deque(range(1, N + 1)) + cnt = 1 + ret = [] + while len(queue) != 1: + if cnt % 2 == 0: + queue.append(queue.popleft()) + else: + ret.append(queue.popleft()) + cnt += 1 + cnt %= 2 + + ret.append(queue[0]) + return " ".join(map(str, ret)) + + +if __name__ == "__main__": + print(solve(int(input()))) diff --git a/zeta_python/completed/2164.py b/zeta_python/completed/2164.py new file mode 100644 index 0000000..0b0c542 --- /dev/null +++ b/zeta_python/completed/2164.py @@ -0,0 +1,19 @@ +from collections import deque + + +def solve(N): + queue = deque(range(1, N + 1)) + cnt = 1 + while len(queue) != 1: + if cnt % 2 == 0: + queue.append(queue.popleft()) + else: + queue.popleft() + cnt += 1 + cnt %= 2 + + return queue.pop() + + +if __name__ == "__main__": + print(solve(int(input())))