题目内容
某银行将客户分为了若干个优先级, 1 11 级最高, 5 55 级最低,当你需要在银行办理业务时,优先级高的人随时可以插队到优先级低的人的前面。
现在给出一个人员到来和银行办理业务的时间序列,请你在每次银行办理业务时输出客户的编号。
如果同时有多位优先级相同且最高的客户,则按照先来后到的顺序办理。
输入描述
输入第一行是一个正整数 n nn ,表示输入的序列中的事件数量。(1 ≤ n ≤ 500 1\leq n \leq 5001≤n≤500)
接下来有 n nn 行,每行第一个字符为 a aa 或 p pp 。
当字符为 a aa 时,后面会有两个的正整数 n u m numnum 和 x xx ,表示到来的客户编号为 n u m numnum ,优先级为 x xx ;
当字符为 p pp 时,表示当前优先级最高的客户去办理业务。
输出描述
输出包含若干行,对于每个 p pp , 输出一行,仅包含一个正整数 n u m numnum , 表示办理业务的客户编号。
样例
输入:
4
a 1 3
a 2 2
a 3 2
p
输出:2
不保证正确性:
public static void insertBank(){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Map<String,Queue<String>> map = new HashMap<>();
PriorityQueue<int[]> priorityQueue = new PriorityQueue<>(((o1, o2) -> {
return o1[1] - o2[1];
}));
while (in.hasNext()){
String s = in.nextLine();
if (s.startsWith("a")){
String[] s1 = s.split(" ");
Integer num = Integer.valueOf(s1[1]);
Integer pro = Integer.valueOf(s1[2]);
priorityQueue.add(new int[]{num,pro});
}
if (s.startsWith("p")){
int[] poll = priorityQueue.poll();
System.out.println(poll[0]);
}
}
while(!priorityQueue.isEmpty()){
System.out.println(priorityQueue.poll()[0]);
}
}