HDU1873 (queue Application)

Source: Internet
Author: User

[Java]
Package D0725;
 
Import java. util .*;
 
Public class HDU1873 {
 
Public static void main (String [] args ){
Pipeline SC = new pipeline (System. in );
Int n;
Parameter List <Patient> list1;
Parameter List <Patient> list2;
Parameter List <Patient> list3;
While (SC. hasNext ()){
N = SC. nextInt ();
List1 = new parameter list <Patient> ();
List2 = new parameter list <Patient> ();
List3 = new parameter list <Patient> ();
Int id = 1;
While (n --> 0 ){
String str = SC. next ();
// In
If (str. charAt (0) = 'I '){
Int docid = SC. nextInt ();
Int priority = SC. nextInt ();
Patient p = new Patient (id ++, docid, priority );
If (docid = 1 ){
List1.add (p );
Collections. sort (list1 );
} Else if (docid = 2 ){
List2.add (p );
Collections. sort (list2 );
} Else {
List3.add (p );
Collections. sort (list3 );
}
 
} Else {// out
Int docid = SC. nextInt ();
If (docid = 1 ){
If (list1.isEmpty ())
System. out. println ("EMPTY ");
Else
System. out. println (list1.poll (). id );
} Else if (docid = 2 ){
If (list2.isEmpty ())
System. out. println ("EMPTY ");
Else
System. out. println (list2.poll (). id );
} Else {
If (list3.isEmpty ())
System. out. println ("EMPTY ");
Else
System. out. println (list3.poll (). id );
}
 
}
 
}
}
}
 
}
 
Class Patient implements Comparable <Patient> {
Public int docId;
Public int priority;
Public int id;
 
Public Patient (int id, int docId, int priority ){
This. id = id;
This.doc Id = docId;
This. priority = priority;
}
 
@ Override
Public int compareTo (Patient o ){
If (this. priority> = o. priority)
Return-1;
Return 1;
}
 
} [Java]
Package D0725;
 
Import java. util .*;
 
Public class HDU1873 {
 
Public static void main (String [] args ){
Pipeline SC = new pipeline (System. in );
Int n;
Parameter List <Patient> list1;
Parameter List <Patient> list2;
Parameter List <Patient> list3;
While (SC. hasNext ()){
N = SC. nextInt ();
List1 = new parameter list <Patient> ();
List2 = new parameter list <Patient> ();
List3 = new parameter list <Patient> ();
Int id = 1;
While (n --> 0 ){
String str = SC. next ();
// In
If (str. charAt (0) = 'I '){
Int docid = SC. nextInt ();
Int priority = SC. nextInt ();
Patient p = new Patient (id ++, docid, priority );
If (docid = 1 ){
List1.add (p );
Collections. sort (list1 );
} Else if (docid = 2 ){
List2.add (p );
Collections. sort (list2 );
} Else {
List3.add (p );
Collections. sort (list3 );
}
 
} Else {// out
Int docid = SC. nextInt ();
If (docid = 1 ){
If (list1.isEmpty ())
System. out. println ("EMPTY ");
Else
System. out. println (list1.poll (). id );
} Else if (docid = 2 ){
If (list2.isEmpty ())
System. out. println ("EMPTY ");
Else
System. out. println (list2.poll (). id );
} Else {
If (list3.isEmpty ())
System. out. println ("EMPTY ");
Else
System. out. println (list3.poll (). id );
}
 
}
 
}
}
}
 
}
 
Class Patient implements Comparable <Patient> {
Public int docId;
Public int priority;
Public int id;
 
Public Patient (int id, int docId, int priority ){
This. id = id;
This.doc Id = docId;
This. priority = priority;
}
 
@ Override
Public int compareTo (Patient o ){
If (this. priority> = o. priority)
Return-1;
Return 1;
}
 
}

Author: lhfight
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.