114514(手写栈逝葴恴汼疈)

蒙自市凤凰小学又阝十尃亻二  •  1年前


include<bits/stdc++.h>

using namespace std; const int n=1e5+5; int a[n],top=0; bool isempty(){

return !top; 

} void push(int x){

a[++top]=x;

} int pop(){

if(!isempty())
return a[--top];

} int Top(){

if(!isempty())
return a[top];

} int main(){

int n,x,y;
cin>>n;
for(int i=0;i<n;i++){
	cin>>x;
	if(x==1){
		cin>>y;
		push(y);
	}else if(x==2){
		pop();
	}else{
		cout<<Top()<<endl;
	}
}
return 0;

}


评论:

请先登录,才能进行评论