114514(手写栈逝葴恴汼疈)

蒙自市凤凰小学又阝十尃亻二 · 发布于 2023-05-02 · 浏览 582 回复 0

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;

}

全部回复 共 0 条

还没有人回复。往下写第一条。

发表回复