本蒟蒻手搓了一个数组当栈,因为不会用STL库
代码如下:
#include<bits/stdc++.h>
using namespace std;
unsigned long long int a[10000005],top = 0,n;
int main(){
long long times;
cin >> times;
for(int i = 1;i <= times;i++){
cin >> n;
top = 0;
for(int j = 1; j <= n;j++){
string oper;
cin >> oper;
if(oper == "push"){
int num;
cin >> num;
a[top++] = num;
continue;
}
if(oper == "query"){
if(top){
cout << a[top - 1];
}else{
cout << "Anguei!";
}
}
if(oper == "pop"){
if(top){
top--;
continue;
}else{
cout << "Empty";
}
}
if(oper == "size"){
cout << top;
}
cout << endl;
}
}
return 0;
}
测试点1AC;2、3WA