Day 8 :Dictionaries and Maps
Solution In Java 8:
import java.util.*;import java.io.*;
class Solution{
public static void main(String []argh){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
HashMap <String,Integer> hm = new HashMap<String,Integer>();
for(int i = 0; i < n; i++){
String name = in.next();
int phone = in.nextInt();
hm.put(name,phone);
}
while(in.hasNext()){
String s = in.next();
if(hm.containsKey(s))
{
System.out.println(s+"="+hm.get(s));
}
else{
System.out.println("Not found");
}
}
in.close();
}
}
Solution In Python 3:
n = int(input().strip())
D = {}
for x in range(n):
l = input()
k,v = l.split()
D[k] = v
for x in range(len(D)):
l = input()
if l in D.keys():
print("{}={}".format(l ,D[l]))
else:
print("Not found")
0 comments:
Post a Comment