社区讨论

求助

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

讨论操作

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

当前回复
1 条
当前快照
1 份
快照标识符
@m5tn9w3s
此快照首次捕获于
2025/01/12 21:22
去年
此快照最后确认于
2025/11/04 11:42
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
int T;
int n;
string s;
stack<int>st; 

int main()
{
	cin>>T;
	while(T--)
	{
		while(!st.empty())st.pop();
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>s;
			if(s=="push")
			{
				int x;
				cin>>x;
				st.push(x); 	
			}
			if(s=="query")
			{
				if(!st.empty())cout<<st.top()<<"\n\n";
				else cout<<"Anguei!\n\n"; 
			}
			if(s=="size")cout<<st.size()<<"\n\n";
			if(s=="pop")
			{
				if(!st.empty())st.pop();
				else cout<<"Empty\n\n";
			}
		}
	}

	return 0;
}

回复

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

正在加载回复...