forked from sknsht/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
25 lines (21 loc) · 713 Bytes
/
Solution.java
File metadata and controls
25 lines (21 loc) · 713 Bytes
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
import java.util.*;
class Solution {
public static void main(String[] argh) {
Scanner in = new Scanner(System.in);
HashMap<String, Integer> phoneBook = new HashMap<>();
int n = in.nextInt();
in.nextLine();
for (int i = 0; i < n; i++) {
String name = in.nextLine();
int phone = in.nextInt();
phoneBook.put(name, phone);
in.nextLine();
}
while (in.hasNext()) {
String name = in.nextLine();
String result = Optional.ofNullable(phoneBook.get(name))
.map(phone -> name + "=" + phone).orElse("Not found");
System.out.println(result);
}
}
}