zengyanbin @ 2024-09-21 22:35:29
有没有大神找出错哪了!
#include<iostream>
#include<stack>
using namespace std;
stack<int> q;
int main(){
unsigned long long t, n, x;
string h;
cin>>t;
for(unsigned long long i1=1;i1<=t;i1++){
cin>>n;
for(unsigned long long i=1;i<=n;i++){
cin>>h;
if(h=="push"){
cin>>x;
q.push(x);
}else if(h=="pop"){
if(q.empty()){
cout<<"Empty"<<endl;
}else{
q.pop();
}
}else if(h=="query"){
if(q.empty()){
cout<<"Empty"<<endl;
}else{
q.top();
}
}else if(h=="size"){
cout<<q.size()<<endl;
}
}
}
return 0;
}
by M_C_Yyyds @ 2024-09-22 13:17:25
@zengyanbin
#include<bits/stdc++.h>
using namespace std;
unsigned long long n,m;
stack<unsigned long long int> s;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>m;
for(int j=1;j<=m;j++){
string h;
cin>>h;
if(h=="push"){
unsigned long long x;
cin>>x;
s.push(x);
}
if(h=="query"){
if(s.empty()){
cout<<"Anguei!\n";
}
else cout<<s.top()<<"\n";
}
if(h=="size"){
cout<<s.size()<<"\n";
}
if(h=="pop"){
if(s.empty()){
cout<<"Empty\n";
}
else s.pop();
}
}
}
return 0;
}
dong?
by zengyanbin @ 2024-09-27 18:58:50
@M_C_Yyyds 感谢大神回复
by M_C_Yyyds @ 2024-09-27 20:15:38
@zengyanbin 求互关