hdu 1873 看病排队

来源:互联网 发布:淘宝充300抢150的攻略 编辑:程序博客网 时间:2024/06/02 22:42

这是我第一次做队列的题目,比较好理解,比较简单,一开始没有重载运算符。wa了几次。。。。

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<cstdio>
using namespace std;


struct IN{
    int num;   //编号
    int b;      //病危级别
   friend bool operator<(IN n1,IN n2)  重载运算符
    {
        if(n1.b==n2.b)  return n2.num<n1.num;
        else                return n1.b<n2.b;
    }
};


int main()
{
   int N;
   string s;
   IN in;
while(cin>>N)
{
    priority_queue<IN>d[4];
    int j=0;
   for(int i=0;i<N;i++)
   {
       cin>>s;
       if(s=="IN")
       {
          int a;
          cin>>a>>in.b;
          in.num=++j;
          d[a].push(in);
       }
       else
       {
           int k;
         cin>>k;
         if(d[k].empty())  cout<<"EMPTY"<<endl;
         else{
             in=d[k].top();
             d[k].pop();
             cout<<in.num<<endl;
         }


       }
   }
}
   return 0;


}

原创粉丝点击