B3614 【模板】栈

B3614 【模板】栈_第1张图片

#include 
#define ull unsigned long long
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        stack st;
        int n;
        cin >> n;
        while(n--)
        {
            string s;
            cin >> s;
            ull a;
            if(s == "push") cin >> a;
            if(s == "push") st.push(a);
            else if(s == "pop")
            {
                if(!st.empty()) st.pop();
                else    cout << "Empty" << endl;
            }
            else if(s == "query")
            {
                if(!st.empty()) cout << st.top() << endl;
                else    cout << "Anguei!" << endl;
            }
            else    cout << st.size() << endl;
        }
    }
    return 0;
}

 

你可能感兴趣的:(c++,洛谷)