萌新手写栈 66 分求助
查看原帖
萌新手写栈 66 分求助
1079073
Hatsunatsu楼主2023/11/22 11:11

RT,一开始拿 33 分发现需要用 unsigned long long int; 修改后 66 分,希望神犇指出。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

typedef unsigned long long int ll;

const int MAXN=1e6+10;
const int MOD=1e9+7;

ll a[MAXN],t;

void push(ll n){
	a[t++]=n;
}

void pop(){
	t--;
}

ll top(){
	return a[t-1];
}

ll size(){
	return t;
}

bool empty(){
	return t==0;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll T;
	cin>>T;
	while(T--){
		ll n;
		cin>>n;
		while(n--){
			string x;
			cin>>x;
			if(x=="push"){
				ll y;
				cin>>y;
				push(y);
			}
			else if(x=="pop"){
				if(!empty()){
					pop(); 
				}
				else{
					cout<<"Empty\n";
				}
			}
			else if(x=="query"){
				if(!empty()){
					cout<<top()<<"\n";
				}
				else{
					cout<<"Anguei!\n";
				}
			}
			else if(x=="size"){
				cout<<size()<<"\n";
			}
		}
	}
	return 0;
} 
2023/11/22 11:11
加载中...