Advertisement
deyanmalinov

06. A Miner Task

Apr 2nd, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.util.LinkedHashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         LinkedHashMap<String, Integer> resurs = new LinkedHashMap<>();
  9.         String line = scan.nextLine();
  10.         while (!line.equals("stop")){
  11.             String fline = line;
  12.             String sLine = scan.nextLine();
  13.             if (!resurs.containsKey(fline)){
  14.                 resurs.put(fline, Integer.parseInt(sLine));
  15.             }else {
  16.                 resurs.put(fline, resurs.get(fline)+ Integer.parseInt(sLine));
  17.             }
  18.             line=scan.nextLine();
  19.         }
  20.         for (Map.Entry<String, Integer> entry : resurs.entrySet()) {
  21.             System.out.println(entry.getKey() + " -> " +entry.getValue());
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement