Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner= new Scanner(System.in);
- HashMap<String, String> hashMap = new HashMap<>();
- String[] broevi = scanner.nextLine().split(" ");
- int n = Integer.parseInt(broevi[0]);
- int m = Integer.parseInt(broevi[1]);
- for (int i=0;i<n;i++)
- {
- String [] niza = scanner.nextLine().split(" ");
- String ime = niza[0];
- String brojka = niza[1];
- if (hashMap.containsKey(ime))
- {
- if (!hashMap.get(ime).contains(brojka))
- hashMap.put(ime, hashMap.get(ime) + " " + brojka);
- }
- else
- hashMap.put(ime,brojka);
- }
- for (int i=0;i<m;i++) {
- String[] niza = scanner.nextLine().split(" ");
- String ime = niza[0];
- String brojka = niza[1];
- if (hashMap.containsKey(ime)) {
- if (!hashMap.get(ime).contains(brojka))
- hashMap.put(ime, hashMap.get(ime) + " " + brojka);
- } else
- hashMap.put(ime, brojka);
- // System.out.println(hashMap.get(ime));
- }
- for (Map.Entry<String, String> entry : hashMap.entrySet())
- {
- if (entry.getValue().split(" ").length >=2)
- System.out.println(entry.getKey() + " "+ entry.getValue() );
- }
- }
- }
- /*
- Input
- 3 3
- jessie 25000
- jackie 22000
- ashley 20000
- jessie 30000
- jackie 25000
- john 18000
- Output
- jessie 25000 30000
- jackie 22000 25000
- */
Advertisement
Add Comment
Please, Sign In to add comment