Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Concert {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Map<String, List<String>> bands = new LinkedHashMap<>();
- Map<String, Integer> bandPlayTime = new TreeMap<>();
- String input = sc.nextLine();
- while (!input.equals("start of concert")) {
- String[] tokens = input.split("[; |, ]{2}");
- String command = tokens[0];
- String bandName = tokens[1];
- // List<String> bandMembers = Arrays.asList(tokens[2].split(", "));
- if (command.equals("Add")) {
- for (int i = 2; i < tokens.length; i++) {
- if (!bands.containsKey(bandName)) {
- bands.put(bandName, new ArrayList<>());
- bands.get(bandName).add(tokens[i]);
- } else {
- if (!bands.get(bandName).contains(tokens[i])) {
- bands.get(bandName).add(tokens[i]);
- }
- }
- }
- } else {
- int time = Integer.parseInt(tokens[2]);
- if (!bandPlayTime.containsKey(bandName)) {
- bandPlayTime.put(bandName, time);
- } else {
- bandPlayTime.put(bandName, bandPlayTime.get(bandName) + time);
- }
- }
- input = sc.nextLine();
- }
- int totalTime = 0;
- for (Integer value : bandPlayTime.values()) {
- totalTime += value;
- }
- System.out.println("Total time: " + totalTime);
- bandPlayTime.entrySet().stream().sorted((f,s) -> {
- int result = s.getValue() - f.getValue();
- if (result == 0) {
- f.getKey().compareTo(s.getKey());
- }
- return result;
- }).forEach(entry -> System.out.printf("%s -> %d%n", entry.getKey(), entry.getValue()));
- String band = sc.nextLine();
- for (Map.Entry<String, List<String>> entry : bands.entrySet()) {
- if (entry.getKey().equals(band)) {
- System.out.println(entry.getKey());
- entry.getValue().forEach(s -> System.out.printf("=> %s%n", s));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement