Skip to content

Commit

Permalink
CT_293
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-Good committed Oct 26, 2024
1 parent c58ec0d commit 7515705
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions BOJ/Java/src/S4/Boj_14612_김식당.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package S4;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Boj_14612_김식당 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());

int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());

ArrayList<Order> list = new ArrayList<>();

for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());

String str = st.nextToken();

if (str.equals("order")) {

list.add(new Order(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())));

} else if (str.equals("sort")) {

list.sort((o1, o2) -> {
if (o1.time != o2.time) {
return o1.time - o2.time;
}
return o1.table - o2.table;
});

} else {
int target = Integer.parseInt(st.nextToken());

for (int j = 0; j < list.size(); j++) {
if (list.get(j).table == target) {
list.remove(j);
break;
}
}
}

if (!list.isEmpty()) {
for (Order o : list) {
sb.append(o.table).append(' ');
}
sb.append('\n');
} else {
sb.append("sleep\n");
}
}

bw.write(sb.toString());
bw.flush();
}

private static class Order implements Comparable<Order> {
int table;
int time;

public Order(int table, int time) {
this.table = table;
this.time = time;
}

public int compareTo(Order o) {
if (this.time != o.time) {
return this.time - o.time;
}
return this.table - o.table;
}
}
}

0 comments on commit 7515705

Please sign in to comment.