栈求助
查看原帖
栈求助
374523
JustinJQian楼主2021/9/16 19:18

求帮忙

#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack <int> a;
int find(){
	stack <int> b;
	int maxn=0;
	b = a;
	while(!b.empty()){
		if(b.top()>maxn) maxn = b.top();
		b.pop();
	}
	cout << maxn;
	return maxn;
}
int main(){
	
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		char c;
		c = getchar();
		if (c == '0') {int x;cin >> x,a.push(x);}
		else if(c == '1') a.pop();
		else if(c == '2' ) find();
		
	}
	return 0;
} 
2021/9/16 19:18
加载中...