#include #include #include #include #include using namespace std; typedef unsigned long long ULL; const int N=1e6+10; ULL s[N]; int top;//指针 void push(ULL x){//入 if(top<N){//条件判断 防止栈满 top++; s[top]=x; } } void pop(){//出 if(top>0){//栈不为空 top--; }else{ cout<<"Empty"<<endl; } } void query(){ if(top>0){ cout<<s[top]<<endl; }else{ cout<<"Anguei!"<<endl; } } int size(){ return top; } void clear(){ top=0; } int main(){ int T;//组数 cin>>T; while(T--){ int n;//操作次数 cin>>n; clear(); while(n--){//循环处理每组的n个操作 string s;//操作指令 cin>>s; if(s=="push") { ULL x; cin>>x; push(x);//入栈 }else if(s=="pop"){ pop(); } else if(s=="query"){ query(); } else if(s=="size"){ cout<<size()<<endl;// 输出栈内元素个数 } } } return 0; }

0 条评论

目前还没有评论...

信息

ID
1966
时间
ms
内存
MiB
难度
2
标签
递交数
246
已通过
48
上传者