Advertisement
i_graurov

concert

Apr 1st, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.HashMap;
  3. import java.util.LinkedHashMap;
  4. import java.util.Scanner;
  5.  
  6. public class concert {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. String[] input = scanner.nextLine().split("; ");
  10. LinkedHashMap<String,ArrayList<String>> concertMembers = new LinkedHashMap<>();
  11. HashMap<String,Integer> concertTime = new HashMap<>();
  12. int totalTime = 0;
  13. while (!input[0].equals("start of concert")){
  14. String bandName = input[1];
  15. String command = input[0];
  16. switch (command){
  17. case "Add":
  18. concertMembers.putIfAbsent(bandName,new ArrayList<>());
  19. String[] members = input[2].split(", ");
  20. for (int i = 0; i < members.length; i++) {
  21. if (!concertMembers.get(bandName).contains(members[i])){
  22. concertMembers.get(bandName).add(members[i]);
  23. }
  24. }
  25. break;
  26. case "Play":
  27. int time = Integer.parseInt(input[2]);
  28. totalTime +=time;
  29. if (concertTime.containsKey(bandName)){
  30. int currentTime = concertTime.get(bandName);
  31. concertTime.put(bandName,time+currentTime);
  32. } else {
  33. concertTime.putIfAbsent(bandName,time);
  34. }
  35. break;
  36. }
  37. input = scanner.nextLine().split("; ");
  38. }
  39. System.out.printf("Total time: %d%n",totalTime);
  40. concertTime
  41. .entrySet()
  42. .stream()
  43. .sorted((h1,h2)-> {
  44. int result = h2.getValue()-h1.getValue();
  45. if (result ==0){
  46. result = h1.getKey().compareTo(h2.getKey());
  47. }
  48. return result;
  49. })
  50. .forEach(e-> System.out.printf("%s -> %d%n",e.getKey(),e.getValue()));
  51. String wichGroup = scanner.nextLine();
  52. if (concertMembers.containsKey(wichGroup)){
  53. System.out.println(wichGroup);
  54. for (int i = 0; i < concertMembers.get(wichGroup).size(); i++) {
  55. System.out.printf("=> %s%n",concertMembers.get(wichGroup).get(i));
  56. }
  57.  
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement