感觉思路没问题啊?怎么就爆零了?
查看原帖
感觉思路没问题啊?怎么就爆零了?
1000433
humingming楼主2024/8/13 16:33
#include<bits/stdc++.h>
using namespace std;
stack<int> a;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	while(n--){
		int x;
		cin>>x;
		if(x==0){
			int y;
			cin>>y;
			a.push(y);
		}
		else if(x==1){
			a.pop();
		}	
		else{
			int maxx=0;
			stack<int> temp;
			for(int i=1;i<=a.size();i++){
				if(a.top()>maxx) maxx=a.top();
				temp.push(a.top());
				a.pop();
			}
			for(int i=1;i<=temp.size();i++)
				a.push(temp.top()),temp.pop();
			cout<<maxx<<endl;	
		}
	}
	return 0;
}
2024/8/13 16:33
加载中...