HDU1873(队列应用)
[java]
package D0725;
import java.util.*;
public class HDU1873 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
LinkedList<Patient> list1;
LinkedList<Patient> list2;
LinkedList<Patient> list3;
while (sc.hasNext()) {
n = sc.nextInt();
list1 = new LinkedList<Patient>();
list2 = new LinkedList<Patient>();
list3 = new LinkedList<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.docId = docId;
this.priority = priority;
}
@Override
public int compareTo(Patient o) {
if (thi
补充:软件开发 , Java ,