社区讨论

40求佬调

B3614【模板】栈参与者 2已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@mlqo12vs
此快照首次捕获于
2026/02/17 21:55
前天
此快照最后确认于
2026/02/18 21:04
15 小时前
查看原帖
CPP
//【模板】栈
#include<bits/stdc++.h>
using namespace std;
unsigned long long x;
long long T,n;
string s;
stack <unsigned long long>st;
int main (){
cin >> T;
while(T--){
	cin >> n;
	while(n--){
		cin >> s; 
		if(s == "push"){
			cin >> x;
			st.push(x);
		}
		else if(s== "pop"){
			if(st.empty()){
				cout << "Empty"<<endl;
			}else{
			st.pop();
		}
		}
		else if(s=="query"){
			if(st.empty()){
				cout << "Angeui!"<<endl;
			}else{
			cout << st.top() << endl;
			}
		}
		else if(s=="size"){
			cout << st.size() << endl;
		}
	}
	while(!st.empty()){
		st.pop();
	}
}
return 0;
}

回复

3 条回复,欢迎继续交流。

正在加载回复...