forked from upupming/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1022 Digital Library (30).java
66 lines (60 loc) · 2.42 KB
/
1022 Digital Library (30).java
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
58
59
60
61
62
63
64
65
66
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.TreeSet;
public class Main {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 6 * 1024 * 1024);
static class Library {
HashMap<String, TreeSet<String>>[] allMaps = new HashMap[5];
Library() throws IOException {
for (int i = 0; i < 5; i++) {
HashMap<String, TreeSet<String>> map = new HashMap<>(1000, 1);
allMaps[i] = map;
}
int record_size = Integer.valueOf(reader.readLine());
for (int i = 0; i < record_size; i++) {
String id = reader.readLine();
for (int j = 0; j < allMaps.length; j++) {
HashMap<String, TreeSet<String>> map = allMaps[j];
if (j == 2) {
String[] keys = reader.readLine().split(" ");
for (String key : keys) {
putValue(map, key, id);
}
} else {
String key = reader.readLine();
putValue(map, key, id);
}
}
}
}
TreeSet<String> query(int id, String queryString) {
HashMap<String, TreeSet<String>> allMap = allMaps[id - 1];
TreeSet<String> integers = allMap.get(queryString);
return integers;
}
private void putValue(HashMap<String, TreeSet<String>> map, String key, String id) {
TreeSet<String> integers = map.computeIfAbsent(key, k -> new TreeSet<>());
integers.add(id);
}
}
public static void main(String[] args) throws IOException {
Library library = new Library();
int query_size = Integer.valueOf(reader.readLine());
for (int i = 0; i < query_size; i++) {
String line = reader.readLine();
System.out.println(line);
int id = line.charAt(0) - 48;
String query = line.substring(3);
TreeSet<String> queryResult = library.query(id, query);
if (queryResult == null) {
System.out.println("Not Found");
} else {
for (String book_id : queryResult) {
System.out.println(book_id);
}
}
}
}
}