Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner scn = new Scanner(System.in);
- int n = Integer.parseInt(scn.nextLine());
- TreeMap<String, TreeMap<String, Long>> companies = new TreeMap<>();
- for (int i = 0; i < n; i++) {
- String[] line = scn.nextLine().split("\\s+");
- String company = line[0];
- String nuts = line[1];
- Long amount = Long.parseLong(line[2].replaceAll("kg", ""));
- if (!companies.containsKey(company)) {
- companies.put(company, new TreeMap<>());
- }
- Long count = companies.get(company).get(nuts);
- if (count == null) {
- count = 0l;
- }
- companies.get(company).put(nuts, amount + count);
- }
- System.out.println(companies);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement