Advertisement
mirozspace

Concert

Mar 31st, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. Map<String, List<String>> members = new LinkedHashMap<>();
  8. Map<String, Integer> time = new HashMap<>();
  9.  
  10. String line = scanner.nextLine();
  11.  
  12. while (!(line.equals("start of concert"))) {
  13. String[] arrayLine = line.split("; ");
  14. String nameOfGroup = arrayLine[1];
  15. if (arrayLine[0].equals("Add")) {
  16.  
  17. if (!(members.containsKey(nameOfGroup))) {
  18. members.put(nameOfGroup, new ArrayList<>());
  19. List<String> temp = members.get(nameOfGroup);
  20. String[] arrTemp = arrayLine[2].split(", ");
  21. Collections.addAll(temp, arrTemp);
  22. } else {
  23. List<String> temp = members.get(nameOfGroup);
  24. String[] arrTemp = arrayLine[2].split(", ");
  25. for (String s : arrTemp) {
  26. if (!(temp.contains(s))) {
  27. temp.add(s);
  28. }
  29. }
  30. }
  31. } else if (arrayLine[0].equals("Play")) {
  32. int songTime = Integer.parseInt(arrayLine[2]);
  33. if (!(time.containsKey(nameOfGroup))) {
  34. time.put(nameOfGroup, songTime);
  35. } else {
  36. time.put(nameOfGroup, time.get(nameOfGroup) + songTime);
  37. }
  38. }
  39. line = scanner.nextLine();
  40. }
  41.  
  42. int totalTime = 0;
  43. for (Map.Entry<String, Integer> time1 : time.entrySet()) {
  44. totalTime += time1.getValue();
  45. }
  46.  
  47. String nameOfGroup = scanner.nextLine();
  48.  
  49. System.out.println("Total time: " + totalTime);
  50.  
  51. time
  52. .entrySet()
  53. .stream()
  54. .sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
  55. .forEach(time1 -> System.out.println(String.format("%s -> %s", time1.getKey(), time1.getValue())));
  56.  
  57. System.out.println(nameOfGroup);
  58.  
  59. members
  60. .forEach((key, value) -> {
  61. if (key.equals(nameOfGroup)) {
  62. value.forEach(e -> System.out.println("=> " + e));
  63. }
  64. });
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement