当前位置: 代码迷 >> 综合 >> (优先队列)hdu1509 Windows Message Queue
  详细解决方案

(优先队列)hdu1509 Windows Message Queue

热度:100   发布时间:2023-11-02 19:23:36.0

题目链接:(优先队列)hdu1509 Windows Message Queue

#include<iostream>
#include<queue>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
const int maxn = 2010;
const int INF=0x3f3f3f3f;typedef struct Node{char name[100]; //不知道为什么,用string类型放进优先队列里总是出错int w,c,id;bool operator < (const Node &A)const{if(c!=A.c) return c>A.c;return id>A.id;}
}Node;
Node tmp;int main()
{priority_queue<Node> pq;char s[5];int r=0;while(~scanf("%s",s)){if(strcmp(s,"GET")==0){if(pq.empty()){printf("EMPTY QUEUE!\n");}else{tmp=pq.top();printf("%s %d\n",tmp.name,tmp.w);pq.pop();}}else{scanf("%s%d%d",tmp.name,&tmp.w,&tmp.c);tmp.id=r;r++;pq.push(tmp);}}return 0;
}

 

  相关解决方案