大佬超时求助求助呜呜呜呜呜
查看原帖
大佬超时求助求助呜呜呜呜呜
455511
gxlover楼主2023/5/16 11:49
#include<iostream>
#include<string>
#include<cstdio> 
using namespace std;
const int N = 100030;
unsigned long long int mystack[N];
int st=-1;//栈顶
//插入新元素 
void push(unsigned long long int x){
	mystack[++st] = x;
}
//弹出栈元素 
void pop(){
	if(st==-1){
		printf("Empty\n");
	}else{
		st--;
	}
}
//输出栈的大小 
void size(){
	printf("%d\n",st+1);
}
unsigned long long int query(){
	if(st==-1){
		printf("Anguei!\n");
	}else{
		printf("%lld\n",mystack[st]);
	}
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		while(n--){
			string op;
			cin >> op;
			if(op=="push"){
				unsigned long long int x;
				cin>>x;
//				scanf("%llu",&x);
				push(x); 
			}else if(op=="pop"){
				pop();
			}else if(op=="query"){
				query();
			}else if(op=="size"){
				size();
			}
		}
//		st = -1;
	}
}

求大佬们看一下,最后栈顶指针要不要重置为-1

2023/5/16 11:49
加载中...