forked from alexanderscott/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphone-book.java
More file actions
38 lines (31 loc) · 1.02 KB
/
Copy pathphone-book.java
File metadata and controls
38 lines (31 loc) · 1.02 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
// https://www.hackerrank.com/challenges/phone-book
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) {
HashMap<String, Integer> phoneBook = new HashMap<String, Integer>();
Scanner in = new Scanner(System.in);
int entries = 0;
int i = 0;
while(in.hasNextLine()) {
if (i == 0) {
entries = Integer.parseInt(in.nextLine());
} else if (i <= entries) {
String key = in.nextLine();
int num = Integer.parseInt(in.nextLine());
phoneBook.put(key, num);
} else {
String key = in.nextLine();
if (phoneBook.containsKey(key)) {
System.out.println(key + "=" + phoneBook.get(key));
} else {
System.out.println("Not found");
}
}
i += 1;
}
}
}