Advertisement
Guest User

Untitled

a guest
Nov 6th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. Scanner scn = new Scanner(System.in);
  2. int n = Integer.parseInt(scn.nextLine());
  3.  
  4. TreeMap<String, TreeMap<String, Long>> companies = new TreeMap<>();
  5.  
  6. for (int i = 0; i < n; i++) {
  7. String[] line = scn.nextLine().split("\\s+");
  8. String company = line[0];
  9. String nuts = line[1];
  10. Long amount = Long.parseLong(line[2].replaceAll("kg", ""));
  11.  
  12. if (!companies.containsKey(company)) {
  13. companies.put(company, new TreeMap<>());
  14. }
  15.  
  16. Long count = companies.get(company).get(nuts);
  17. if (count == null) {
  18. count = 0l;
  19. }
  20. companies.get(company).put(nuts, amount + count);
  21.  
  22. }
  23. System.out.println(companies);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement