T270730 栈 代码求助
  • 板块学术版
  • 楼主llxsmy_forever
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/10/16 12:40
  • 上次更新2023/10/27 07:17:11
查看原帖
T270730 栈 代码求助
664779
llxsmy_forever楼主2022/10/16 12:40
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
	LL t;scanf("%lld",&t);
	while(t--)
	{
		LL n;scanf("%lld",&n);
		stack<LL>q;
		while(n--)
		{
			char s[10];
			scanf("%s",s+1);
			if(s[1]=='p'&&s[2]=='u')
			{
				LL x;scanf("%lld",&x);
				q.push(x);
			}
			else if(s[1]=='p')
			{
				if(!q.empty()) q.pop();
				else printf("Empty\n");
			}
			else if(s[1]=='q')
			{
				if(!q.empty()) printf("%lld\n",q.top());
				else printf("Anguei!\n");
			}
			else printf("%lld\n",q.size());
		}
	}
	return 0;
}
2022/10/16 12:40
加载中...