Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedHashMap;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class Nuts {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = Integer.parseInt(sc.nextLine());
- TreeMap<String, LinkedHashMap<String, Integer>> orders = new TreeMap<>();
- for (int i = 0; i < n; i++) {
- String[] input = sc.nextLine().split(" ");
- String kg = input[2].substring(0, input[2].length() - 2);
- int kilogrammes = Integer.parseInt(kg);
- if (orders.containsKey(input[0])) {
- if (orders.get(input[0]).containsKey(input[1])) {
- int currentKg = orders.get(input[0]).get(input[1]);
- orders.get(input[0]).put(input[1], currentKg + kilogrammes);
- } else {
- orders.get(input[0]).put(input[1], kilogrammes);
- }
- } else {
- LinkedHashMap<String, Integer> currentOrder = new LinkedHashMap<>();
- currentOrder.put(input[1], kilogrammes);
- orders.put(input[0], currentOrder);
- }
- }
- for (String string : orders.keySet()) {
- System.out.print(string + ": ");
- int i = 0;
- for (String string2 : orders.get(string).keySet()) {
- int kg = orders.get(string).get(string2);
- System.out.print(string2 + "-" + kg + "kg");
- if (i < orders.get(string).size() - 1) {
- System.out.print(", ");
- }
- i++;
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement