求助,样例能过,实则#2错误
查看原帖
求助,样例能过,实则#2错误
663693
chenjieyang楼主2022/8/24 21:49
#include<iostream>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
long long t,n,x,ctrl;
string c;
stack<long long>s;
int main(){
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>n;
        for(int j=1;j<=n;j++){
            cin>>c;
            if(c=="push"){
                cin>>x;
                s.push(x);
            }
            if(c=="pop"){
                if(s.empty()){
                    cout<<"Empty"<<endl;
                }else{
                    s.pop();
                }
            }
            if(c=="query"){
                if(s.empty()){
                    cout<<"Anguei!"<<endl;
                }else{
                    cout<<s.top()<<endl;
                }
            }
            if(c=="size"){
                cout<<s.size()<<endl;
            }
        }
        while(!s.empty())s.pop();
    }
    return 0;
}
2022/8/24 21:49
加载中...