HDOJ 5349 MZL's simple problem 【set】

HDOJ 5349 MZL’s simple problem 【set】

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5349


set常用场景:operator选择功能实现

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
int N;
int op, opn;
multiset<int> s; // 元素可重复
multiset<int>::iterator it;

void output(){
    it = s.begin();
    while(it != s.end())
        cout<<*it++<<"\t";
    cout<<endl;
}

int main(){
    scanf("%d", &N);
    while(N--){
        scanf("%d", &op);
        if(op == 1){
            scanf("%d", &opn);
            s.insert(opn);
            //output();
        }
        else if(op == 2){
            if(!s.empty()){
                s.erase(*s.begin());
                //output();
            }
        }
        else{
            if(s.empty())
                printf("0\n");
            else
                printf("%d\n", *--s.end()); // end为最后一个元素的下一个指针
        }
    }

    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2015-08-04 19:25  快扶哀家去刷题  阅读(147)  评论(0编辑  收藏  举报