AcWing 828. 模拟栈python3
原题链接
简单
作者:
xanxus1111
,
2020-04-28 17:10:40
,
所有人可见
,
阅读 604
h, idx= [0]*100010, 0
def push(x):
global idx
h[idx] = x
idx += 1
def pop():
global idx
idx -= 1
def empty():
global idx
if idx == 0:
return 'YES'
return 'NO'
def query():
global idx
return h[idx-1]
def operate(s):
op = s.split()[0]
if op == 'push':
x = s.split()[1]
push(x)
elif op == 'pop':
pop()
elif op == 'empty':
print(empty())
elif op == 'query':
print( query())
if __name__ == "__main__":
n = int(input())
for i in range(n):
s = input()
operate(s)