栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1371 MANAGER

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1371 MANAGER

#include<iostream>#include<queue>#include<cstdio>#include<cctype>#include<string.h> using namespace std;enum {    SIZ = 10008,};int num; int most; int cur;  int top; int s, e; int cnt[SIZ];int ord[SIZ];bool small;void add(){    int v;    scanf("%d", &v);    cnt[v]++;    if(s > e){        s = e = v;    } else {        s = min(s, v);        e = max(e, v);    }}int getVal(){    int v;    if(s > e){        return -1;    }    v = (small?s:e);    cnt[v]--;    for(; s<=e&&cnt[s]==0; s++)        ;    for(; e>=s&&cnt[e]==0; e--)        ;    return v;}void remove(){    int v = getVal();    if(top < num && (cur++ == ord[top])){        printf("%dn", v);        top++;    }}void fun(){    char op;    small = true;    scanf(" %c", &op);    while(op != 'e'){        if(op=='a'){ add();        } else if(op=='r'){ remove();        }else if(op =='p'){ int t; scanf("%d", &t); small = (t==1);        }        scanf(" %c", &op);    }}int readIn(){    if(scanf("%d", &most) < 0) return 0;    int i;    cur = 1;    top = 0;    scanf("%d", &num);    for(i=0; i<num; i++){        scanf("%d", &ord[i]);    }    for(i=0; i<= most; i++){        cnt[i] = 0;    }    s = SIZ, e = -1;    return 1;}int main(){    int tst=0;    while(readIn() > 0){        if(tst++) printf("n");        fun();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371616.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号