Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- import java.util.Scanner;
- public class concert {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split("; ");
- LinkedHashMap<String,ArrayList<String>> concertMembers = new LinkedHashMap<>();
- HashMap<String,Integer> concertTime = new HashMap<>();
- int totalTime = 0;
- while (!input[0].equals("start of concert")){
- String bandName = input[1];
- String command = input[0];
- switch (command){
- case "Add":
- concertMembers.putIfAbsent(bandName,new ArrayList<>());
- String[] members = input[2].split(", ");
- for (int i = 0; i < members.length; i++) {
- if (!concertMembers.get(bandName).contains(members[i])){
- concertMembers.get(bandName).add(members[i]);
- }
- }
- break;
- case "Play":
- int time = Integer.parseInt(input[2]);
- totalTime +=time;
- if (concertTime.containsKey(bandName)){
- int currentTime = concertTime.get(bandName);
- concertTime.put(bandName,time+currentTime);
- } else {
- concertTime.putIfAbsent(bandName,time);
- }
- break;
- }
- input = scanner.nextLine().split("; ");
- }
- System.out.printf("Total time: %d%n",totalTime);
- concertTime
- .entrySet()
- .stream()
- .sorted((h1,h2)-> {
- int result = h2.getValue()-h1.getValue();
- if (result ==0){
- result = h1.getKey().compareTo(h2.getKey());
- }
- return result;
- })
- .forEach(e-> System.out.printf("%s -> %d%n",e.getKey(),e.getValue()));
- String wichGroup = scanner.nextLine();
- if (concertMembers.containsKey(wichGroup)){
- System.out.println(wichGroup);
- for (int i = 0; i < concertMembers.get(wichGroup).size(); i++) {
- System.out.printf("=> %s%n",concertMembers.get(wichGroup).get(i));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement