complete 2161.py 2164.py 10845.py 18258.py
This commit is contained in:
36
zeta_python/completed/10845.py
Normal file
36
zeta_python/completed/10845.py
Normal file
@@ -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)
|
||||||
36
zeta_python/completed/18258.py
Normal file
36
zeta_python/completed/18258.py
Normal file
@@ -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)
|
||||||
21
zeta_python/completed/2161.py
Normal file
21
zeta_python/completed/2161.py
Normal file
@@ -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())))
|
||||||
19
zeta_python/completed/2164.py
Normal file
19
zeta_python/completed/2164.py
Normal file
@@ -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())))
|
||||||
Reference in New Issue
Block a user