Advertisement
i_graurov

SoftUniKaraoke

Apr 1st, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class SoftUniKaraoke {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. String[] input1 = scanner.nextLine().split(",\\s+");
  7. List<String> singers = Arrays.asList(input1);
  8. String[] input2 = scanner.nextLine().split(",\\s+");
  9. List<String> songs = Arrays.asList(input2);
  10. String[] awards = scanner.nextLine().split(",\\s+");
  11. HashMap<String, ArrayList<String>> karaokeAwards = new HashMap<>();
  12.  
  13. while (!"Dawn".equals(awards[0])) {
  14. if (awards.length == 3) {
  15. String name = awards[0];
  16. String song = awards[1];
  17. String award = awards[2];
  18. if (singers.contains(name) && songs.contains(song)) {
  19. karaokeAwards.putIfAbsent(name, new ArrayList<>());
  20. if (karaokeAwards.containsKey(name) && !karaokeAwards.get(name).contains(award)) {
  21. karaokeAwards.get(name).add(award);
  22. }
  23. }
  24. }
  25. awards = scanner.nextLine().split(",\\s+");
  26.  
  27. }
  28. if (karaokeAwards.isEmpty()){
  29. System.out.println("No awards");
  30. }
  31.  
  32. karaokeAwards
  33. .entrySet()
  34. .stream()
  35. .sorted((h1,h2)-> {
  36. int result = h2.getValue().size() - h1.getValue().size();
  37. if (result==0){
  38. result = h1.getKey().compareTo(h2.getKey());
  39. }
  40. return result;
  41. })
  42. .forEach(e-> {
  43. System.out.printf("%s: %d awards%n",e.getKey(),e.getValue().size());
  44. for (int i = 0; i < e.getValue().size(); i++) {
  45. System.out.printf("--%s%n",e.getValue().get(i));
  46. }
  47. });
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement