66pts 求调

B3614 【模板】栈

liujunyua @ 2024-10-07 20:27:00

#include<iostream>
#include<string>
#include<stack>
using namespace std;
stack<unsigned   long long > st;
int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        while(n--){
            string od;
            unsigned long long x;
            cin>>od;
            if(od=="push"){
                cin>>x;
                st.push(x);
            }
            if(od=="pop"){
                if(!st.empty())
                  st.pop();
                else
                  cout<<"Empty"<<'\n';
            }
            if(od=="query"){
                if(!st.empty()) 
                cout<<st.top()<<'\n';
                else
                cout<<"Anguei!"<<'\n';
            }   
            if(od=="size")
               cout<<st.size()<<'\n';
        }
    }
    return 0;
}

模板栈 总是wa一点 66pts 求调


by libu2333 @ 2024-10-07 20:39:39

#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
    int T;
    cin>>T;
    for(int i=0;i<T;i++){
        int n;
        cin>>n;
        stack<unsigned long long> st;
        for(int j=0;j<n;j++){

            string od;
            unsigned long long x;
            cin>>od;
            if(od[0]=='p'&&od[1]=='u'){
                cin>>x;
                st.push(x);
            }
            if(od[0]=='p'&&od[1]=='o'){
                if(!st.empty())
                  st.pop();
                else
                  cout<<"Empty"<<endl;
            }
            if(od[0]=='q'){
                if(!st.empty()) 
                    cout<<st.top()<<endl;
                else
                    cout<<"Anguei!"<<endl;
            }   
            if(od[0]=='s')
               cout<<st.size()<<endl;
        }
    }
    return 0;

}

@liujunyua


by masonxiong @ 2024-10-07 20:51:51

@liujunyua

典中典之多测不清空。


|