-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrandpabernie.java
55 lines (45 loc) · 1.05 KB
/
grandpabernie.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
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
public class grandpabernie {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
HashMap<String, ArrayList<Integer>> places = new HashMap<>();
HashSet<String> record = new HashSet<>();
int p = scan.nextInt();
scan.nextLine();
while(p -- > 0)
{
String str = scan.next();
record.add(str);
int year = scan.nextInt();
scan.nextLine();
if(places.containsKey(str))
{
places.get(str).add(year);
}
else
{
ArrayList<Integer> nums = new ArrayList<>();
nums.add(year);
places.put(str, nums);
}
}
for(String s : record)
{
Collections.sort(places.get(s));
}
int q = scan.nextInt();
scan.nextLine();
while(q --> 0)
{
String str = scan.next();
int time = scan.nextInt();
scan.nextLine();
System.out.println(places.get(str).get(time-1));
}
scan.close();
}
}