9 solutions

  • 0
    @ 2022-1-1 23:54:44

    我是蒟蒻1111

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n;
    	string wuhu;
    	cin>>n;
    	while(n--)
    	{
    		stack<int> s;
    		int m,n;
    		cin>>m;
    		for(int i=1;i<=m;i++)
    		{
    			cin>>wuhu;
    			if(wuhu=="pop")
    			{
    				if(s.empty())
    				cout<<"Empty"<<endl;
    				else{
    					cout<<s.top()<<endl;//先入后出 
    					s.pop(); //记得弹出 
    				}
    			}
    			else
    			{
    				int a;
    				cin>>a;
    				s.push(a);
    			 } 
    	}
    }
    	return 0;
    }
    

    Information

    ID
    330
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    2
    Tags
    # Submissions
    152
    Accepted
    48
    Uploaded By