49分求调
查看原帖
49分求调
960459
__lalala__楼主2023/7/12 14:44

cpp```

#include<bits/stdc++.h>
using namespace std;
int top = 0;
int a[100010], b[100010], stk[100010];
int main()
{
	int n;
	cin >> n;
	int i = 0;
	while(i<n)
	{
		cin >>a[i];
		if(a[i]==0)
		{
			cin >> b[i];
			top++;
			stk[top] = b[i];
		}
		if(a[i]==1)
		{
			if(top!=0)
			{
				top--;
			}
		}
		if(a[i]==2)
		{
			if(top==0)
			{
				cout << 0 << "\n";
			}else
			{
				int max = stk[1];
				for(int j = 1;j <= top;j++)
				{
					if(max < stk[j])
					{
						max = stk[j];
					}
				}
				cout << max << "\n";
			}
		}
		i++;
	}
	return 0;
}
2023/7/12 14:44
加载中...