Advertisement
Guest User

Exam Problem - Nuts

a guest
Nov 6th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. package Problem04;
  2.  
  3. import java.util.Scanner;
  4. import java.util.TreeMap;
  5.  
  6. public class Nuts {
  7. public static void main(String[] args) {
  8. // Writing The Input
  9. Scanner scn = new Scanner(System.in);
  10. int n = Integer.parseInt(scn.nextLine());
  11.  
  12. TreeMap<String, TreeMap<String, int[]>> companies = new TreeMap<>();
  13.  
  14. for (int i = 0; i < n; i++) {
  15. String[] line = scn.nextLine().split("\\s+");
  16. String company = line[0];
  17. String nuts = line[1];
  18. String amount = line[2];
  19.  
  20. if (!companies.containsKey(company)) {
  21. companies.put(company, new TreeMap<>());
  22. }
  23. if (!companies.get(company).containsKey(nuts)) {
  24. companies.get(company).put(nuts,new int[1]);
  25. }
  26.  
  27. // Writing The Output:
  28. // Expected Output
  29. //EatYourNuts: almonds-30kg, brazilnuts-15kg
  30. //KingNuts: almonds-250kg
  31. //Rois: cashews-14kg, wallnuts-28 kg
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement