题解 | #堆栈的使用#

堆栈的使用

https://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26

#include <bits/stdc++.h>

using namespace std;
stack<int> stk;

int main(){
	int n;
	while (cin >> n){
		while (n --){
			string op;
			cin >> op;
			if (op == "P"){
				int x;
				cin >> x;
				stk.push(x);
			}
			else if (op == "O"){
				if (!stk.empty()) stk.pop();
			}
			else{
				if (stk.empty()) puts("E");
				else printf("%d\n", stk.top());
			}
		}
	}
	return 0;
}

全部评论

相关推荐

06-27 15:29
门头沟学院 Java
点赞 评论 收藏
分享
05-09 14:45
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务