首页 > 代码库 > hdu 1908 Double Queue (map)

hdu 1908 Double Queue (map)

# include <stdio.h>
# include <algorithm>
# include <iostream>
# include <string.h>
# include <string>
# include <map>
using namespace std;
int main()
{

    map<int,int>q;
    map<int,int>::iterator p;
    int n,name,num;
    while(~scanf("%d",&n),n)
    {
        if(n==1)
        {
            scanf("%d%d",&name,&num);
            q.insert(pair<int,int>(num,name));///自动按num从小到大
        }
        else if(n==3)///按num小的输出
        {
            if(q.size())
            {
                p=q.begin();///取第一个
                printf("%d\n",p->second);
                q.erase(p);///删除
            }
            else
                printf("0\n");
        }
        else
        {
            if(q.size())
            {

                printf("%d\n",q.rbegin()->second);///取最后一个
                q.erase(q.find(q.rbegin()->first));

            }
            else
                printf("0\n");
        }
    }
    return 0;
}

hdu 1908 Double Queue (map)