记录编号 610582 评测结果 AAAAA
题目名称 1141.[湖北2011寒假] 求M数 最终得分 100
用户昵称 Gravatarfirefly 是否通过 通过
代码语言 C++ 运行时间 0.902 s
提交时间 2026-01-13 20:06:16 内存使用 3.85 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
stack<int> stk;
int main() {
    freopen("allm.in","r",stdin);
    freopen("allm.out","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int s;
        scanf("%d",&s);
        while(!(stk.empty())){
            if(stk.top()<s){
                printf("%d ",stk.top());
                stk.push(s);
                break;
            }else{
                stk.pop();
            }
        }
        if(stk.empty()){
            stk.push(s);
            printf("%d ",0);
        }
    }
    return 0;
}