You are viewing a single comment's thread. Return to all comments →
import java.util.*; import java.io.*; class Solution{ public static void main(String []argh){ Scanner in = new Scanner(System.in); int n = in.nextInt(); Map<String, Integer> phone_book = new HashMap<>(); int get_phone; for(int i = 0; i < n; i++){ String name = in.next(); int phone = in.nextInt(); phone_book.put(name, phone); } while(in.hasNext()){ String s = in.next(); if(phone_book.containsKey(s)){ get_phone = phone_book.get(s); System.out.println(s + "=" + get_phone); } else { System.out.println("Not found"); } } in.close(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 8: Dictionaries and Maps
You are viewing a single comment's thread. Return to all comments →