社区讨论

20分求调样例过了

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

讨论操作

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

当前回复
8 条
当前快照
1 份
快照标识符
@mhjignz9
此快照首次捕获于
2025/11/04 03:06
4 个月前
此快照最后确认于
2025/11/04 03:06
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
stack <int> st;
unsigned long long x,T,n;
string a;
int main() 
{
	cin>>T;
	for(int i=0;i<T;i++)
	{
		while (!st.empty()) 
    		st.pop();
		cin>>n;
		for(int j=0;j<n;j++)
		{
			cin>>a;
			if(a=="push")
			{
				cin>>x;
				st.push(x);
			}
			if(a=="query")
			{
				if(!st.empty()) cout<<st.top()<<endl;
				else cout<<"Anguei!"<<endl;
			}
			if(a=="size")
			{
				if(!st.empty()) cout<<"0"<<endl;
				else cout<<st.size()<<endl;
			}
			if(a=="pop")
			{
				if(!st.empty()) st.pop();
				else cout<<"Empty"<<endl;
			}
		}
	}
    return 0;
}

回复

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

正在加载回复...