2 solutions

  • 1
    @ 2025-11-30 14:06:35
    #include<bits/stdc++.h>
    using namespace std;
    const int N=100010;
    int stk[N],tt=0; 
    int main()
    {
    	int n;
    	cin>>n;
    	string str;
    	while(n--)
    	{
    		cin>>str;
    		if(str=="push")
    		{
    			int x;
    			cin>>x;
    			stk[++tt]=x;
    		}
    		else if(str=="pop") tt--;
    		else if(str=="query") cout<<stk[tt]<<endl;
    		else if(str=="empty")
    		{
    			if(tt>0)
    			{
    				cout<<"NO"<<endl;
    			}
    			else cout<<"YES"<<endl;
    		}
    	}
    	return 0;
    }
    
    
    

    Information

    ID
    169
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    1
    Tags
    # Submissions
    87
    Accepted
    25
    Uploaded By