33pts求调
查看原帖
33pts求调
554001
QuQi_ZhouSi楼主2024/6/26 08:16
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read(){
    int sz=0,zf=1;
    char ch=0;
    while(ch<'0'||ch>'9'){
        if(ch=='-') zf=-1;
        ch=getchar();
    }
    while (ch>='0'&&ch<='9'){
        sz=sz*10+(ch-'0');
        ch=getchar();
    }
    return sz*zf;
}


signed main(){
    int T=read(),x;
    while(T--){
        stack<int> st;
        int Q=read();
        while(Q--){
            char s[10];
            scanf("%s",s);
            if(strcmp(s,"push")==0) x=read(),st.push(x);
            else if(strcmp(s,"size")==0) printf("%lld",st.size()),puts("");
            else if(strcmp(s,"pop")==0){
                if(st.empty()) puts("Empty");
                else st.pop();
            }
            else if(strcmp(s,"query")==0){
                if(st.empty()) puts("Anguei!");
                else printf("%lld",st.top()),puts("");
            }
        }
    }
    return 0;
}
2024/6/26 08:16
加载中...