社区讨论

请大佬帮蒟蒻Debug一下

B3614【模板】栈参与者 3已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@lpjc9fg7
此快照首次捕获于
2023/11/29 13:40
2 年前
此快照最后确认于
2023/11/29 18:03
2 年前
查看原帖

代码如下

CPP
#include<iostream>
#include<string.h>
#include<cstdlib>
using namespace std;
const int N=1e6+1;
int stack[N]; 
int t;
int top=0;
void push(int x){
	top++;
	stack[top]=x;
	return;
}
void pop(){
	if(top==0){
		printf("Empty\n");
	}else{
		top--;
	}
	return;
}
void query(){
	if(top==0){
		printf("Anguei!\n");
	}else{
		printf("%d\n",stack[top]);
	}
}
void size(){
	printf("%d\n",top);
}
int main(){
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		int n;
		scanf("%d",&n);
		for(int j=0;j<n;j++){
			string s;
			cin>>s;
			if(s=="push"){
				int x;
				scanf("%d",&x);
				push(x);
			}
			if(s=="pop"){
				pop();
			}
			if(s=="query"){
				query();
			}
			if(s=="size"){
				size();
			}
		}
		top=0;
		memset(stack,0,sizeof(stack));
	}
	return 0;
} 

附:点1AC 点2、3WA

请大佬赐教!

回复

2 条回复,欢迎继续交流。

正在加载回复...