Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class _01_Concert {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, List<String>> bandsMembers = new LinkedHashMap<>();
- Map<String, Integer> bandsTimes = new HashMap<>();
- String input = "";
- while (!"start of concert".equals(input = scanner.nextLine())) {
- String[] line = input.split("; ");
- String command = line[0];
- String band = line[1];
- String[] memb = line[2].split(", ");
- if (command.equals("Add")) {
- bandsMembers.putIfAbsent(band, new ArrayList<>());
- List<String> members = bandsMembers.get(band);
- for (int i = 0; i < memb.length; i++) {
- if (!members.contains(memb[i])) {
- members.add(memb[i]);
- }
- }
- bandsTimes.putIfAbsent(band, 0);
- } else if (command.equals("Play")) {
- int time = Integer.parseInt(line[2]);
- bandsTimes.putIfAbsent(band, 0);
- bandsTimes.put(band, bandsTimes.get(band) + time);
- }
- }
- int sum = 0;
- for (Map.Entry<String, Integer> entry : bandsTimes.entrySet()) {
- sum += entry.getValue();
- }
- System.out.println("Total time: " + sum);
- bandsTimes.entrySet()
- .stream()
- .sorted(Map.Entry.<String, Integer>comparingByValue().reversed()
- ).forEach(e -> {
- System.out.printf("%s -> %d%n", e.getKey(), e.getValue());
- });
- String bandListing = scanner.nextLine();
- bandsMembers.entrySet()
- .stream()
- .sorted((x, y) -> Integer.compare(y.getValue().size(), x.getValue().size()))
- .forEach(e -> {
- if (e.getKey().equals(bandListing)) {
- System.out.println(e.getKey());
- for (int i = 0; i < e.getValue().size(); i++) {
- System.out.printf("=> %s%n", e.getValue().get(i));
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement