Sort by

recency

|

366 Discussions

|

  • + 0 comments

    Simple solution

    class Solution{
    	public static void main(String []argh)
    	{
    		Scanner in = new Scanner(System.in);
    		int n=in.nextInt();
    		in.nextLine();
            Map<String, Integer> mp = new HashMap<>();
    		for(int i=0;i<n;i++)
    		{
    			String name=in.nextLine();
    			int phone=in.nextInt();
                mp.put(name, phone);
    			in.nextLine();
    		}
            
    		while(in.hasNext())
    		{
    			String s=in.nextLine();
                if (mp.containsKey(s)) {
                    System.out.println(s + "=" + mp.get(s));
                } else {
                    System.out.println("Not found");
                }
    		}
    	}
    }
    
  • + 0 comments
    import java.util.*;
    import java.io.*;
    
    class Solution{
    	public static void main(String []argh)
    	{
    		Scanner in = new Scanner(System.in);
            HashMap<String, String> phoneBook = new HashMap<>();
    		int n=in.nextInt();in.nextLine();
    		for(int i=0;i<n;i++)
                {phoneBook.put(in.nextLine(),in.nextLine());}
    		while(in.hasNext())
    		{
    			String s=in.nextLine();
                if (phoneBook.containsKey(s))
                    {System.out.printf("%s=%s%n",s,phoneBook.get(s));}
                else {System.out.println("Not found");}
    		}
    	}
    }
    
  • + 0 comments
    class Solution{
    	public static void main(String []argh)
    	{
    		Scanner in = new Scanner(System.in);
    		int n=in.nextInt();
    		in.nextLine();
            Map<String, Integer> m = new HashMap<>();
    		for(int i=0;i<n;i++)
    		{
    			String name=in.nextLine();
    			int phone=in.nextInt();
    			in.nextLine();
                m.put(name, phone);
    		}
    		while(in.hasNext())
    		{
    			String s=in.nextLine();
                if(m.containsKey(s)){
                    System.out.println(s+'='+m.get(s));
                }else{
                    System.out.println("Not found");
                }
    		}
    	}
    }
    
  • + 0 comments

    //This is my solution, use in case to need class Solution{ public static void main(String []argh) { Scanner in = new Scanner(System.in); int n=in.nextInt(); in.nextLine(); Map find = new HashMap<>(); for(int i=0;i

  • + 0 comments

    Java 8:

    public static void main(String []argh)
    	{
    		Scanner in = new Scanner(System.in);
    		int n=in.nextInt();
    		in.nextLine();
            Map<String, Integer> phoneDirectoryMap = new HashMap<>();
    		for(int i=0;i<n;i++)
    		{
    			String name=in.nextLine();
    			int phone=in.nextInt();
    			in.nextLine();
                phoneDirectoryMap.put(name, phone);
    		}
    		while(in.hasNext())
    		{
    			String s=in.nextLine();
                if (phoneDirectoryMap.containsKey(s)) {
                    System.out.println(s + "=" + phoneDirectoryMap.get(s));
                } else {
                    System.out.println("Not found");
                }
    		}
    	}