-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotelSearcher.java
More file actions
76 lines (62 loc) · 1.63 KB
/
HotelSearcher.java
File metadata and controls
76 lines (62 loc) · 1.63 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class HotelSearcher {
static class HotelDetails implements Comparable<HotelDetails> {
public HotelDetails(int id, int matches) {
super();
this.id = id;
this.matches = matches;
}
int id;
int matches;
@Override
public int compareTo(HotelDetails o) {
if (o != null) {
return o.matches - this.matches;
}
return 0;
}
}
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String s = br.readLine();
String[] words = s.split(" ");
Set<String> set = new HashSet<String>(Arrays.asList(words));
int numHot = Integer.parseInt(br.readLine());
Map<Integer, HotelDetails> map = new HashMap<>();
for (int i = 0; i < numHot; i++) {
int id = Integer.parseInt(br.readLine());
String[] revWords = br.readLine().split(" ");
int count = 0;
for (String str1 : revWords) {
if (set.contains(str1)) {
count++;
}
}
if (map.get(id) != null) {
HotelDetails hd = map.get(id);
hd.matches = hd.matches + count;
} else {
map.put(id, new HotelDetails(id, count));
}
}
List<HotelDetails> list = new ArrayList<>(map.values());
Collections.sort(list);
for (HotelDetails hd : list) {
System.out.print(hd.id + " ");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}