不会呀!!!
查看原帖
不会呀!!!
1432277
limoxuan0712楼主2025/1/17 12:05

此为RE超人:

#include<bits/stdc++.h>
#define int long long
using namespace std;
stack<int> st;
void Pop(stack<int> st){
	if(st.empty()) printf("Empty");
	else st.pop();
}
void Query(stack<int> st){
	if(st.empty()) printf("Anguei!");
	else printf("%d",st.top());
}
signed main(){
	int t;
	scanf("%d",&t);
	for(int i=1;i<=t;i++){
		while(!st.empty()){
			st.pop();
		}
		int n;
		scanf("%d",&n);
		for(int j=1;j<=n;j++){
			string str;
			scanf("%s",&str);
			if(str=="push"){
				int x;
				scanf("%d",&x);
				st.push(x);
			}else if(str=="pop"){
				Pop(st);
			}else if(str=="query"){
				Query(st);
			}else{
				printf("%d",st.size());
			}
		}
	}
	return 0;
}

听取WA声一片:

#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
stack<int> st;
void Pop(stack<int> st){
	if(st.empty()) cout<<"Empty"<<endl;
	else st.pop();
}
void Query(stack<int> st){
	if(st.empty()) cout<<"Anguei!"<<endl;
	else cout<<st.top()<<endl;
}
signed main(){
	int t;
	cin>>t;
	for(int i=1;i<=t;i++){
		while(!st.empty()){
			st.pop();
		}
		int n;
		cin>>n;
		for(int j=1;j<=n;j++){
			string str;
			cin>>str;
			if(str=="push"){
				long long x;
				cin>>x;
				st.push(x);
			}else if(str=="pop"){
				Pop(st);
			}else if(str=="query"){
				Query(st);
			}else{
				cout<<st.size()<<endl;
			}
		}
	}
	return 0;
}

Help!Help!

2025/1/17 12:05
加载中...