zoj - 2724 - Windows Message Queue

题意:PUT为存入,GET为取队头查询,不停地存入与取队头元素,输出相应的信息即可。

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1724

——>>之前见题目的通过率只有26.65%,又赶时间,早早地跳过了这题,刚刚看了下,用优先队列一试,原来是那么水的……无语

#include <iostream>
#include <queue>

using namespace std;

struct node     //定义结点数据类型
{
    string name;
    int val;
    int weight;
};

bool operator < (node e1, node e2)      //定义优先队列的排序方式,权值小的在前面
{
    return e1.weight > e2.weight;
}

int main()
{
    string type;        //输入的第一个单词,要么是"GET",要么是"PUT"
    priority_queue<node> qu;        //程序的核心,优先队列
    while(cin>>type)
    {
        if(type == "GET")       //当为读取数据的时候
        {
            if(qu.empty()) cout<<"EMPTY QUEUE!"<<endl;      //队空时
            else        //队不空时
            {
                cout<<qu.top().name<<" "<<qu.top().val<<endl;
                qu.pop();
            }
        }
        else        //当为存取数据的时候
        {
            node newnode;
            cin>>newnode.name>>newnode.val>>newnode.weight;     //入列
            qu.push(newnode);
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值