33分帮助
查看原帖
33分帮助
664234
I_AM_THREE_BODY_MAN楼主2023/10/9 12:58

请各位大佬帮忙找错 垃圾代码:

#include <bits/stdc++.h>
using namespace std;
stack<int> st;
signed main(){
    int t;
	cin>>t;
    while(t--){
        int n;
		cin>>n;
        for(int i=1;i<=n;i++){
            int x;
            string op;
			cin>>op;
            if(op=="push"){
                cin>>x;
                st.push(x);
            }
            if(op=="pop"){
                if(!st.empty()) st.pop();
                else cout<<"Empty"<<endl;
            }
            if(op=="query"){
                if(!st.empty()) cout<<st.top()<<endl;
                else cout<<"Anguei!"<<endl;
            }
            if(op=="size") cout<<st.size()<<endl;
        }
        while (!st.empty()) st.pop();
    }
    return 0;
}
2023/10/9 12:58
加载中...