-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_17254.java
More file actions
54 lines (45 loc) · 1.65 KB
/
Copy pathBOJ_17254.java
File metadata and controls
54 lines (45 loc) · 1.65 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
// BOJ - 17254
// Problem Sheet - https://www.acmicpc.net/problem/17254
import java.util.*;
import java.io.*;
public class Main {
static class Log implements Comparable<Log> {
private final int keyboard;
private final int time;
private final char input;
public Log(int keyboard, int time, char input) {
this.keyboard = keyboard;
this.time = time;
this.input = input;
}
public int getKeyboard() { return this.keyboard; }
public int getTime() { return this.time; }
public char getInput() { return this.input; }
@Override
public int compareTo(Log l) {
if (this.time == l.getTime()) {
return this.keyboard - l.getKeyboard();
}
return this.time - l.getTime();
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder sb = new StringBuilder();
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
List<Log> logs = new ArrayList<>(m);
for (int i=0 ; i<m ; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
char c = st.nextToken().charAt(0);
logs.add(new Log(a, b, c));
}
Collections.sort(logs);
logs.forEach(l -> sb.append(l.getInput()));
System.out.println(sb);
br.close();
}
}