社区讨论
30分(样例过了)有调必关
B3614【模板】栈参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mhqm4rj2
- 此快照首次捕获于
- 2025/11/09 02:23 3 个月前
- 此快照最后确认于
- 2025/11/16 14:06 3 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
#define int long long
int T,q,zhan[1000010],head;
signed main()
{
cin>>T;
while(T--)
{
head=0;
cin>>q;
for(int i=1;i<=q;i++)
{
string s;
int x;
cin>>s;
if(s=="push")
cin>>x,zhan[++head]=x;
else if(s=="pop")
if(head==0)
cout<<"Empty"<<endl;
else
head--;
else if(s=="query")
if(head==0)
cout<<"Anguei!"<<endl;
else
cout<<zhan[head]<<endl;
else
cout<<head<<endl;
}
}
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...