33分超时,求调
查看原帖
33分超时,求调
1404123
liuruihang2027楼主2024/9/16 21:04

求助各位大佬,程序超时了

#include<bits/stdc++.h>
using namespace std;
stack <int> st;
int n,x,m,y;
string chos;
int main() {
    cin>>n;
    for (int i=1;i<=n;i++)
    {
    	cin>>x;
        for (int i=1;i<=x;i++)
        {
        	cin>>chos;
            if (chos=="push")
            {
            	cin>>y;
                st.push (y);
            }
            else if (chos=="pop")
            {
            	if (st.empty())
                	cout<<"Empty"<<endl;
                else    
            		st.pop();
            }
            else if (chos=="query")
            {
            	if (st.empty())
                	cout<<"Anguei!"<<endl;
                else    
                	cout<<st.top()<<endl;
            }
            else
            	cout<<st.size()<<endl;
        }
        while (!st.empty())
        	st.top();
    }
    return 0;
}
2024/9/16 21:04
加载中...