You are viewing a single comment's thread. Return to all comments →
public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); Map<String, Integer> phoneBook = new HashMap<>(); for(int i=0; i<n; i++){ String name = br.readLine().trim(); int phoneNumber = Integer.parseInt(br.readLine().trim()); phoneBook.put(name, phoneNumber); } String query; StringBuilder sb = new StringBuilder(); while((query = br.readLine())!=null && !query.isEmpty()){ if(phoneBook.containsKey(query)){ sb.append(query+"="+phoneBook.get(query)).append("\n"); } else{ sb.append("Not found\n"); } } System.out.println(sb.toString().trim()); }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Java Map
You are viewing a single comment's thread. Return to all comments →
}