Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class _04_Nuts {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int n = Integer.parseInt(input.nextLine());
- Map<String, LinkedHashMap<String, Integer>> nuts = new TreeMap<String, LinkedHashMap<String, Integer>>();
- for (int i = 0; i < n; i++) {
- String[] line = input.nextLine().split(" ");
- String company = line[0];
- String nut = line[1];
- String a = line[2].substring(0, line[2].length() - 2);
- int amount = Integer.parseInt(a);
- if (nuts.containsKey(company)) {
- if (nuts.get(company).containsKey(nut)) {
- int count = nuts.get(company).get(nut).intValue();
- count += amount;
- nuts.get(company).put(nut, count);
- } else {
- nuts.get(company).put(nut, amount);
- }
- } else {
- nuts.put(company, new LinkedHashMap <String, Integer>());
- nuts.get(company).put(nut, amount);
- }
- }
- for (String company : nuts.keySet()) {
- String output = company + ":";
- for (String nut : nuts.get(company).keySet()) {
- output += " " + nut + "-" + nuts.get(company).get(nut).intValue() + "kg,";
- }
- output = output.substring(0,output.length() - 1);
- System.out.println(output);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement