#include<iostream>
#include<stack> //用到栈
#include<string> //用到字符
using namespace std;
int T,n;
string t;
int main(){
ios::sync_with_stdio(false); //提高输出效率,具体可百度
cin.tie(0); //与上行是一个整体
for(cin>>T;T;--T){ //输入T,代表有T组数据
stack<unsigned long long int>s; /*构建栈。unsigned long long int是无符号长整型变量,
是int整型变量中的一类 因为题目的数据比较大所以才用
这个不可以放到 for T的外面,因为每一次数据都不是同一个栈 */
for(cin>>n;n;--n){
cin>>t; //直接以t来代表输入的操作
if(t=="push"){ //记得是双引号
unsigned long long int x; //x是属于栈里边的元素,也要unsigned long long int
cin>>x;
s.push(x); //入栈函数
}
else if(t=="pop"){
if(s.empty()) cout<<"Empty\n"; //如果栈空,用是.empty()
else s.pop(); //出栈函数
}
else if(t=="query"){ // “输出栈顶元素”函数
if(s.empty()) cout<<"Anguei!\n";
else cout<<s.top()<<endl;
}
else cout<<s.size() <<endl; // “输出栈内元素个数"函数
}
}
return 0;
}
09-29
858
04-21
1715
03-14
740
03-13
05-08
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交