Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226186
  • 博文数量: 75
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 848
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-08 10:27
文章分类
文章存档

2014年(9)

2013年(66)

我的朋友

分类: IT职场

2013-11-07 15:09:13

[cpp] view plaincopyprint?
/* 
 * ZOJ_2724.cpp 
 * 
 *  Created on: 2013年11月7日 
 *      Author: Administrator 
 */  
  
#include  
#include  
#include  
#include  
  
using namespace std;  
  
struct MES {  
    char str[10];  
    int mes;  
    int p;  
    int id;  
  
    bool operator<( const MES& b)const {//特别要注意这种写法...  
        if (p != b.p) {  
            return p > b.p;  
        }  
  
        return id > b.id;  
    }  
};  
  
int main() {  
    char s[26];  
    priority_queue q;//对结构体使用优先队列  
    MES tmp;  
    while (scanf("%s", s) != EOF) {  
        int index = 0;  
        if (strcmp(s, "PUT") == 0) {  
            scanf("%s %d %d", tmp.str, &tmp.mes, &tmp.p);  
            tmp.id = index++;  
  
            q.push(tmp);  
 
        } else {  
            if (q.empty()) {  
                printf("EMPTY QUEUE!\n");  
            } else {  
                tmp = q.top();  
                q.pop();  
  
                printf("%s %d\n", tmp.str, tmp.mes);  
            }  
        }  
    }  
  
    return 0;  
}  
阅读(572) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~