Obvious priority queue
I used STL, but I don't fully understand it. I can write a heap estimate myself. I can use it if I have a tool!
# Include < Iostream >
# Include < Queue >
# Include < Vector >
# Include < Stdio. h >
Using Namespace STD;
Const Int Maxn = 60001 ;
Struct Message
{
Char Name [ 20 ];
Int Para, PRI;
Int Order;
Bool Operator < ( Const Message & M1) Const
{
If (PRI = M1.pri)
Return Order > M1.order;
Return PRI < M1.pri;
}
};
Struct CMP
{
Bool Operator ()( Const Message & M1, Const Message & M2 ){
If (M1.pri = M2.pri)
Return M1.order > M2.order;
Return M1.pri > M2.pri;
}
};
// I don't understand the above. I tried it all. c ++ STL has no time to read it!
Priority_queue < Message, Vector < Message > , CMP > Q;
Int Main (){
Char STR [ 5 ], Name [ 20 ];
Int Para, PRI, CNT = 1 ;
While (Scanf ( " % S " , STR) = 1 ){
Switch (STR [ 0 ])
{
Case ' G ' :
If (Q. Empty ())
Printf ( " Empty queue! \ N " );
Else {
Message MOUT = Q. Top ();
Q. Pop ();
Printf ( " % S % d \ n " , MOUT. Name, MOUT. Para );
}
Break ;
Case ' P ' :
Scanf ( " % S % d " , Name, & Para, & PRI );
Message m;
Strcpy (M. Name, name );
M. Para = Para;
M. PRI = PRI;
M. Order = CNT ++ ;
Q. Push (m );
Break ;
}
}
Return 0 ;< BR >}