求改代码
  • 板块题目总版
  • 楼主furina_1013
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/7/30 11:58
  • 上次更新2024/7/30 14:10:12
查看原帖
求改代码
794188
furina_1013楼主2024/7/30 11:58

B3614 【模板】栈

#include<bits/stdc++.h>
using namespace std;
string s;
int t,n;
int top;
unsigned long long  a[1000005],x;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	top=1;
	for(int i=1;i<=t;i++)
	{
		cin>>n;
		for(int j=1;j<=n;j++)
		{
			cin>>s;
			if(s=="push")
			{
				cin>>x;
				a[top]=x;
				top++;
			}
			else if(s=="query")
			{
				if(top==1)cout<<"Anguei!"<<endl;
				else cout<<a[top-1]<<endl;
			}
			else if(s=="size")
			{
				cout<<top-1<<endl;
			}
			else if(s=="pop")
			{
				if(top==1)cout<<"Empty"<<endl;
				else
				{
					a[top-1]=0;
					top--;
				}
			}
		}
	}
	return 0;
 } 
2024/7/30 11:58
加载中...