Advertisement
MoPhreak

Untitled

Mar 20th, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.LinkedHashMap;
  2. import java.util.Scanner;
  3.  
  4. public class MinerTasks {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         LinkedHashMap<String, Integer> quanity = new LinkedHashMap<>();
  9.  
  10.         String input = "";
  11.  
  12.         while (!"stop".equals(input = scanner.nextLine())) {
  13.             String resourse = input;
  14.             int material = Integer.parseInt(scanner.nextLine());
  15.  
  16.             if (!quanity.containsKey(resourse)) {
  17.                 quanity.put(resourse, material);
  18.             } else {
  19.                 quanity.put(resourse, quanity.get(resourse) + material);
  20.             }
  21.         }
  22.         quanity.forEach((key, value) -> {
  23.             System.out.println(String.format("%s -> %d", key, value));
  24.         });
  25.  
  26.  
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement