Sort by

recency

|

368 Discussions

|

  • + 0 comments

    my code:

    //Complete this code or write your own from scratch import java.util.; import java.io.;

    class Solution{ public static void main(String []argh) { Scanner in = new Scanner(System.in); HashMap dict = new HashMap<>();

        int n=in.nextInt();
        in.nextLine();
        for(int i=0;i<n;i++)
        {
            String name=in.nextLine();
            int phone=in.nextInt();
            dict.put(name, phone);
            in.nextLine();
        }
        while(in.hasNext())
        {
            String s=in.nextLine();
            if(dict.containsKey(s)){
                System.out.println(s+"="+dict.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); int n=in.nextInt(); in.nextLine(); Map map=new HashMap<>(); for(int i=0;i

    } }

  • + 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");
                }
    		}
    	}
    }