Java Map Hackkerank

 //Complete this code or write your own from scratch

import java.util.*;
import java.io.*;
import java.util.HashMap;
import java.util.Map.Entry;

class Solution{
    public static void main(String arg[]) throws Exception{
    
        
        InputStreamReader r=new InputStreamReader(System.in);    
        BufferedReader br=new BufferedReader(r);  
        int n=Integer.valueOf(br.readLine());
        if(1<=n && n<=100000){
            HashMap<String,String> aa=new HashMap<String,String>();
            for(int i=0;i<n;i++){
                
                String name=br.readLine();    
                String phone=br.readLine();
                if(phone.length()==8 && phone.charAt(0)!='0'){
                    aa.put(name,phone);
                }
            }
            
            while(n -->0){
                String q;
                while((q=br.readLine())!=null){
                    if(aa.containsKey(q)){
                        String k=q;
                        String val=aa.get(k);
                        System.out.println(k+"="+val);
                        
                    }
                    else {
                        System.out.println("Not found");
                    }
                }
            
            }
            br.close();
        }
    }
}


Thanks for Reading.

Comments

Popular posts from this blog

Solutions Of Practice Questions Dated 01-06-2022

CODEFORCES SPY DETECTED ROUND 713

Maximum Winning Score Geeks For Geeks