Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.lang.reflect.Array;
  4. import java.util.*;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7. import java.util.stream.Collectors;
  8.  
  9. public class Main {
  10. public static void main(String[] args) {
  11. Scanner sc = new Scanner(System.in);
  12.  
  13. Map<String,Integer> times = new LinkedHashMap<>();
  14. Map<String,List<String>> list = new HashMap<>();
  15. boolean isStart = false;
  16. while (!isStart){
  17. String command = sc.nextLine();
  18. if (!command.equals("start of concert")){
  19. String[] input =command.split(";\\s");
  20. String type = input[0];
  21. if (type.equals("Add")){
  22. String bandName = input[1];
  23. String[] members = input[2].split(", ");
  24. if (!list.containsKey(bandName)){
  25. list.put(bandName,new ArrayList<>());
  26.  
  27. for (int i = 0; i < members.length; i++) {
  28. list.get(bandName).add(members[i]);
  29. }
  30.  
  31. }else {
  32. for (int i = 0; i < members.length; i++) {
  33. if (!list.get(bandName).contains(members[i])){
  34. list.get(bandName).add(members[i]);
  35. }
  36. }
  37.  
  38. }
  39.  
  40. }else if (type.equals("Play")){
  41. String bandName = input[1];
  42. int time = Integer.parseInt(input[2]);
  43. times.putIfAbsent(bandName,0);
  44. times.put(bandName,times.get(bandName)+time);
  45. }
  46.  
  47. }else {
  48. isStart = true;
  49. break;
  50. }
  51. }
  52.  
  53. int totalTimes = 0;
  54. for (Map.Entry<String, Integer> entry : times.entrySet()) {
  55. totalTimes += entry.getValue();
  56. }
  57. System.out.printf("Total time: %d%n",totalTimes);
  58. times
  59. .entrySet()
  60. .stream()
  61. .sorted(Map.Entry.<String,Integer>comparingByValue().reversed().thenComparing(Map.Entry.comparingByKey()))
  62. .forEach(s1 -> System.out.printf("%s -> %d%n",s1.getKey(),s1.getValue()));
  63.  
  64. String bandName = sc.nextLine();
  65. if (list.containsKey(bandName)){
  66. System.out.println(bandName);
  67. list
  68. .entrySet()
  69. .stream()
  70. .forEach(s1 -> {
  71. if (s1.getKey().equals(bandName)){
  72. s1.getValue()
  73. .stream()
  74. .forEach(s2 -> System.out.printf("=> %s%n",s2));
  75. }
  76.  
  77. });
  78. }
  79.  
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement