AC但求解释
  • 板块P1165 日志分析
  • 楼主yufh
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/7/30 18:31
  • 上次更新2025/7/30 18:31:44
查看原帖
AC但求解释
1340011
yufh楼主2025/7/30 18:31

AC 代码

#include <bits/stdc++.h>
using namespace std;
/*====================*/
typedef long long ll;
/*====================*/
#define endl '\n'
/*====================*/
const int N=1e5+10;
/*====================*/
int n,stk[N],top;
/*====================*/
void Solve(void)
{
    cin>>n;
    stk[0]=0;
    for(int i=1;i<=n;i++)
    {
        int op;cin>>op;
        if(op==0)
        {
            int x;cin>>x;
            top++;
            stk[top]=max(stk[top-1],x);
        }
        else if(op==1)
        {
            if(top!=0) top--;
        }
        else if(op==2)
        {
            cout<<stk[top]<<endl;
        }
    }

}
/*====================*/
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int T=1;//cin>>T;
    while(T--) Solve();
    return 0;
}

如果把

if(op==0)
{
    int x;cin>>x;
    top++;
    stk[top]=max(stk[top-1],x);
}

改成

if(op==0)
{
    int x;cin>>x;
    stk[++top]=max(stk[top-1],x);
}

就会WA掉

2025/7/30 18:31
加载中...