白俊10828号です.
5299 ワード
白駿10828号スタック
import sys
N=int(sys.stdin.readline())
stack=[]
for _ in range(N):
command=sys.stdin.readline().split()
if command[0]=="push":
stack.append(command[1])
elif command[0]=="pop":
if len(stack)==0:
print("-1")
else:
print(stack.pop())
elif command[0]=="size":
print(len(stack))
elif command[0]=="empty":
if len(stack)==0:
print("1")
else:
print("0")
else:
if len(stack)==0:
print("-1")
else:
print(stack[-1])
input()関数として入力すると、input()ではなくタイムアウトと判定されます.stdin.readline()を使用する場合は、!Reference
この問題について(白俊10828号です.), 我々は、より多くの情報をここで見つけました https://velog.io/@eunyoung23/백준-10828번テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol