-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathphone-book.java
45 lines (37 loc) · 1020 Bytes
/
phone-book.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
// phone book
// 🟢 Easy
// https://www.hackerrank.com/challenges/phone-book/problem?isFullScreen=true
// data structure
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
try {
int no_of_entries = 0;
int i = 0;
String name = null;
int number = 0;
String query = null;
HashMap<String, Integer> phoneBook = new HashMap<String, Integer>();
BufferedReader b = new BufferedReader(new InputStreamReader(
System.in));
no_of_entries = Integer.parseInt(b.readLine());
while (i < no_of_entries) {
name = b.readLine();
number = Integer.parseInt(b.readLine());
phoneBook.put(name, number);
i++;
}
while (!(query = b.readLine().trim()).isEmpty()) {
if (phoneBook.containsKey(query))
System.out.println(query + "=" + phoneBook.get(query));
else
System.out.println("Not found");
}
} catch (Exception e) {
}
}
}