Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- /**
- * Created by grigo on 25.10.2016 г..
- */
- public class AMinerTask {
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- boolean canContinue = true;
- Map<String, Integer> mats = new LinkedHashMap<>();
- while (canContinue) {
- String material = console.nextLine();
- int quantity = 0;
- if (material.equals("stop")) {
- canContinue = false;
- PrintSortedResults(mats);
- break;
- } else {
- quantity = Integer.parseInt(console.nextLine());
- }
- if (mats.containsKey(material)) {
- mats.put(material, mats.get(material) + quantity);
- } else {
- mats.put(material, quantity);
- }
- }
- }
- public static void PrintSortedResults(Map<String, Integer> mats) {
- for (Map.Entry<String, Integer> entry : mats.entrySet()) {
- System.out.printf("%s -> %d\n", entry.getKey(), entry.getValue());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement