解题思路:
注意事项:
参考代码:
def stack_operation(commands):
stack = []
output = []
for command in commands:
if command[0] == 'P':
stack.append(int(command[2:]))
elif command[0] == 'O':
if stack:
stack.pop()
elif command[0] == 'A':
if stack:
output.append(str(stack[-1]))
else:
output.append('E')
return output
while True:
n = int(input())
if n == 0:
break
commands = []
for _ in range(n):
commands.append(input())
result = stack_operation(commands)
print('\n'.join(result))
print()
0.0分
0 人评分