33分蒟蒻求助
  • 板块B3614 【模板】栈
  • 楼主Cha_
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/11/18 14:09
  • 上次更新2023/11/18 15:50:28
查看原帖
33分蒟蒻求助
240497
Cha_楼主2023/11/18 14:09

本蒟蒻手搓了一个数组当栈,因为不会用STL库

代码如下:

#include<bits/stdc++.h>
using namespace std;
unsigned long long int a[10000005],top = 0,n; 
int main(){
	long long times;
	cin >> times;
	for(int i = 1;i <= times;i++){
		cin >> n;
		top = 0;
		for(int j = 1; j <= n;j++){
			string oper;
			cin >> oper;
			if(oper == "push"){
				int num;
				cin >> num;
				a[top++] = num;
				continue;
			}
			if(oper == "query"){
				if(top){
					cout << a[top - 1];
				}else{
					cout << "Anguei!";
				}
			}
			if(oper == "pop"){
				if(top){
					top--;
					continue;
				}else{
					cout << "Empty";
				}
			}
			if(oper == "size"){
				cout << top;
			}
			cout << endl;
		}	
	}
	return 0;
} 

测试点1AC;2、3WA

2023/11/18 14:09
加载中...