nowornever0625 @ 2024-10-06 10:12:24
#include <bits/stdc++.h>
using namespace std;
unsigned long long t, n, x;
string s;
stack<int>st;
int main() {
//freopen("tmp.in", "r", stdin);
cin >> t;
while (t--) {
cin >> n;
while (n--) {
cin >> s;
if (s[2] == 's') {
cin >> x;
st.push(x);
}
if (s[1] == 'o') {
if (st.empty())
cout << "Empty" << endl;
else
st.pop();
}
if (s[0] == 'q') {
if (st.empty())
cout << "Anguei!" << endl;
else
cout << st.top() << endl;
}
if (s[0] == 's')
cout << st.size() << endl;
}
while (!st.empty()) {
st.pop();
}
}
return 0;
}
by Wang_Xu @ 2024-10-06 10:21:10
#include<bits/stdc++.h>
#include<stack>
using namespace std;
stack<unsigned long long int>q;
int n;
int a;
int main(){
cin>>n;
long long v;
for(int i=1;i<=n;i++)
{
cin>>a;
for(int j=1;j<=a;j++)
{
string s;
cin>>s;
if(s=="push")
{
cin>>v;
q.push(v);
}
else if(s=="pop")
{
if(q.empty())
{
cout<<"Empty"<<'\n';
}
else{
q.pop();
}
}
else if(s=="query")
{
if(q.empty())
{
cout<<"Anguei!"<<'\n';
}
else{
cout<<q.top()<<'\n';
}
}
else if(s=="size")
{
cout<<q.size()<<'\n';
}
}
while(q.empty()==false)
{
q.pop();
}
}
return 0;
}
@nowornever0625
by Wang_Xu @ 2024-10-06 10:21:42
@nowornever0625 oi oi oi
by nowornever0625 @ 2024-10-06 10:30:54
@Wang_Xu 能帮我看看,我的代码,哪里有问题吗?
by yuechenxi130407 @ 2024-10-06 10:31:07
#include <bits/stdc++.h>
using namespace std;
vector <unsigned long long> v;
int main() {
int t;
cin>>t;
while (t--){
int n;
cin>>n;
string s;
for (int i=0;i<n;++i){
cin>>s;
if (s=="push"){
unsigned long long x;
cin>>x;
v.push_back(x);
}
else{
if (s=="pop"){
if (v.size())
v.pop_back();
else
cout<<"Empty"<<endl;
}
else if(s=="size"){
cout<<v.size()<<endl;
}
else{
if (!v.size())
cout<<"Anguei!"<<endl;
else
cout<<v[v.size()-1]<<endl;
}
}
}
v.clear();
}
return 0;
}
by yuechenxi130407 @ 2024-10-06 10:31:53
vector yyds!(滑稽)
by nowornever0625 @ 2024-10-06 10:34:22
我终于知道为什么了,变量声明了unsigned long long,结果开栈开成了int,改成unsigned long long,就过了