-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmergencyRoom.java
More file actions
57 lines (46 loc) · 1.28 KB
/
EmergencyRoom.java
File metadata and controls
57 lines (46 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package StackQueue;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
// 다시 풀어보기
public class EmergencyRoom {
static class Person {
int id;
int priority;
public Person(int id, int priority) {
this.id = id;
this.priority = priority;
}
}
public static int solution1(int n, int m, Queue<Person> queue) {
int result = 0;
while (true) {
Person person = queue.poll();
for (Person tmp : queue) {
if (tmp.priority > person.priority) {
queue.offer(person);
person = null;
break;
}
}
if (person != null) {
result++;
if (person.id == m) {
return result;
}
}
}
}
public void main() {
Scanner in=new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
Queue<Person> queue = new LinkedList<>();
for (int i = 0; i < n; i++) {
int temp = in.nextInt();
queue.offer(new Person(i, temp));
}
System.out.println(solution1(n, m, queue));
}
}