HDU 1509 Windows Message Queue
优先队列的基本运用……
#include <cstdio> #include <cstring> #include <queue> using namespace std; struct Message { char Name[100]; int Data,Priority,index; friend bool operator <(const Message &a,const Message &b){ if(a.Priority!=b.Priority)return a.Priority>b.Priority; return a.index>b.index; } }; priority_queue v; int main(){ char command[100]; Message message; int k=0; while(scanf("%s",command)!=EOF){ if(strcmp(command,"GET")==0){ if(v.size()==0)printf("EMPTY QUEUE!\n"); else{ printf("%s %d\n",v.top().Name,v.top().Data); v.pop(); } } else if(strcmp(command,"PUT")==0){ scanf("%s%d%d",message.Name,&message.Data,&message.Priority); message.index=++k; v.push(message); } } return 0; }
愿你出走半生,归来仍是少年