问题描述
- HDU 1509 Windows Message Queue
-
自己测试总刚觉没错,求高手帮忙,不知道哪错了,总wa。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
解决方案
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
class Nod {
String name;
int val, pri;
public Nod(String name, int val, int pri) {
this.name = name;
this.val = val;
this.pri = pri;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
public int getPri() {
return pri;
}
public void setPri(int pri) {
this.pri = pri;
}
}
public class Main4 {
public static void main(String[] args) {
Comparator<Nod> con = new Comparator<Nod>() {
@Override
public int compare(Nod a, Nod b) {
int n1 = a.getPri();
int n2 = b.getPri();
int m1 = a.getVal();
int m2 = b.getVal();
if (n1 > n2) {
return 1;
} else if (n1 < n2) {
return -1;
} else {
return 0;
}
}
};
PriorityQueue<Nod> q = new PriorityQueue<Nod>(con);
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.next();
if (str.equals("GET")) {
if (q.isEmpty()) {
System.out.println("EMPTY QUEUE!");
} else {
Nod n;
n = q.poll();
System.out.println(n.getName() + " " + n.getVal());
}
} else {
String name = sc.next();
int v = sc.nextInt();
int p = sc.nextInt();
Nod n = new Nod(name, v, p);
q.add(n);
}
}
}
}
解决方案二:
hdu 1509 Windows Message Queue......
答案就在这里:hdu 1509 Windows Message Queue
解决方案三:
仔细看看下自己的代码问题已解决,谢谢!
时间: 2024-12-25 14:29:57