社区讨论

33分,为什么!!(求条)

B3614【模板】栈参与者 4已保存回复 5

讨论操作

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

当前回复
5 条
当前快照
1 份
快照标识符
@mhjtkqst
此快照首次捕获于
2025/11/04 08:17
4 个月前
此快照最后确认于
2025/11/04 08:17
4 个月前
查看原帖
上代码!
CPP
#include<bits/stdc++.h>
using namespace std;

int main(){
	int t;
	cin>>t;
	while(t--){
		stack<int> st; 
		int n;
		string s;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>s;
			if(s=="push"){
				unsigned long long k;
				cin>>k;
				st.push(k);
			}
			else if(s=="pop"){
				if(st.empty()){
					cout<<"Empty"<<endl;
				}
				else{
					st.pop();
				}
			}
			else if(s=="query"){
				if(st.empty()){
					cout<<"Anguei!"<<endl;
				}
				else{
					cout<<st.top()<<endl;
				}
			}
			else if(s=="size"){
				cout<<st.size()<<endl;
			}
		}
	}
	return 0;
}
我甚至开了unsigned long long,怎么还没过??求大佬!必关~~

回复

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

正在加载回复...