Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.lang.reflect.Array;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Map<String,Integer> times = new LinkedHashMap<>();
- Map<String,List<String>> list = new HashMap<>();
- boolean isStart = false;
- while (!isStart){
- String command = sc.nextLine();
- if (!command.equals("start of concert")){
- String[] input =command.split(";\\s");
- String type = input[0];
- if (type.equals("Add")){
- String bandName = input[1];
- String[] members = input[2].split(", ");
- if (!list.containsKey(bandName)){
- list.put(bandName,new ArrayList<>());
- for (int i = 0; i < members.length; i++) {
- list.get(bandName).add(members[i]);
- }
- }else {
- for (int i = 0; i < members.length; i++) {
- if (!list.get(bandName).contains(members[i])){
- list.get(bandName).add(members[i]);
- }
- }
- }
- }else if (type.equals("Play")){
- String bandName = input[1];
- int time = Integer.parseInt(input[2]);
- times.putIfAbsent(bandName,0);
- times.put(bandName,times.get(bandName)+time);
- }
- }else {
- isStart = true;
- break;
- }
- }
- int totalTimes = 0;
- for (Map.Entry<String, Integer> entry : times.entrySet()) {
- totalTimes += entry.getValue();
- }
- System.out.printf("Total time: %d%n",totalTimes);
- times
- .entrySet()
- .stream()
- .sorted(Map.Entry.<String,Integer>comparingByValue().reversed().thenComparing(Map.Entry.comparingByKey()))
- .forEach(s1 -> System.out.printf("%s -> %d%n",s1.getKey(),s1.getValue()));
- String bandName = sc.nextLine();
- if (list.containsKey(bandName)){
- System.out.println(bandName);
- list
- .entrySet()
- .stream()
- .forEach(s1 -> {
- if (s1.getKey().equals(bandName)){
- s1.getValue()
- .stream()
- .forEach(s2 -> System.out.printf("=> %s%n",s2));
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement