Crazy

Najpopularni iminja

May 28th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scanner= new Scanner(System.in);
  10.  
  11.  
  12.         HashMap<String, String> hashMap = new HashMap<>();
  13.  
  14.         String[] broevi = scanner.nextLine().split(" ");
  15.  
  16.         int n = Integer.parseInt(broevi[0]);
  17.         int m = Integer.parseInt(broevi[1]);
  18.  
  19.  
  20.         for (int i=0;i<n;i++)
  21.         {
  22.             String [] niza = scanner.nextLine().split(" ");
  23.             String ime = niza[0];
  24.             String brojka =  niza[1];
  25.  
  26.             if (hashMap.containsKey(ime))
  27.             {
  28.                 if (!hashMap.get(ime).contains(brojka))
  29.                     hashMap.put(ime, hashMap.get(ime) + " " + brojka);
  30.             }
  31.             else
  32.                 hashMap.put(ime,brojka);
  33.  
  34.         }
  35.  
  36.         for (int i=0;i<m;i++) {
  37.             String[] niza = scanner.nextLine().split(" ");
  38.             String ime = niza[0];
  39.             String brojka = niza[1];
  40.  
  41.             if (hashMap.containsKey(ime)) {
  42.                 if (!hashMap.get(ime).contains(brojka))
  43.                     hashMap.put(ime, hashMap.get(ime) + " " + brojka);
  44.             } else
  45.                 hashMap.put(ime, brojka);
  46.  
  47.  
  48.            // System.out.println(hashMap.get(ime));
  49.         }
  50.  
  51.  
  52.         for (Map.Entry<String, String> entry : hashMap.entrySet())
  53.         {
  54.             if (entry.getValue().split(" ").length >=2)
  55.                 System.out.println(entry.getKey() + " "+ entry.getValue()   );
  56.         }
  57.  
  58.  
  59.             }
  60.  
  61. }
  62.  
  63.  
  64. /*
  65. Input
  66.  
  67.         3 3
  68.         jessie 25000
  69.         jackie 22000
  70.         ashley 20000
  71.         jessie 30000
  72.         jackie 25000
  73.         john 18000
  74.  
  75. Output
  76.  
  77. jessie 25000 30000
  78. jackie 22000 25000
  79. */
Add Comment
Please, Sign In to add comment