99我
查看原帖
99我
1105563
xuyangming楼主2024/8/8 10:56
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s1,s2; 
int st[1000000+5];
int top=0;
int main()
{
	int t;
	cin>>t;
	while(t--)
    {
		int n;
		cin>>n;
		while(n--)
        {
			string opt;
			cin>>opt;
			if(opt=="push")
            {
				int x;
				cin>>x;
				top++;
				st[top]=x;		
			}
			else if(opt=="pop")
            {
				if(top==0){
					cout<<"Empty\n";
					continue;
				}
				st[top]=0;
				top--;
			}
			else if(opt=="query")
            {
				if(top==0)
                {
					cout<<"Anguei!\n";
					continue;
				}
				cout<<st[top]<<endl;
			}
			else if(opt=="size")
            {
				cout<<top<<endl;
			}
		}
	}
	return 0;
}
2024/8/8 10:56
加载中...