- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerrankJava0033.java
More file actions
Latest commit
35 lines (26 loc) · 823 Bytes
/
Copy pathHackerrankJava0033.java
File metadata and controls
35 lines (26 loc) · 823 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
26
27
28
29
30
31
32
33
34
35
importjava.util.Map;
importjava.util.Scanner;
publicclassHackerrankJava0033 {
publicstaticvoidmain(String[] args) {
// Java Map
// https://www.hackerrank.com/challenges/phone-book/problem?isFullScreen=true
Scannerscanner = newScanner(System.in);
intn = scanner.nextInt();
scanner.nextLine();
Map<String, String> phoneBook = newjava.util.HashMap<String, String>();
for (inti = 0; i < n; i++) {
phoneBook.put(scanner.nextLine(), scanner.nextLine());
}
StringoutputFormat = "%s=%s";
while (scanner.hasNextLine()) {
Stringname = scanner.nextLine();
StringphoneNumber = phoneBook.get(name);
if (phoneNumber == null) {
System.out.println("Not found");
} else {
System.out.println(String.format(outputFormat, name, phoneNumber));
}
}
scanner.close();
}
}