Advertisement
SIRAKOV4444

Untitled

Apr 5th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class lqlq {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. Map<String, ArrayList>menu=new TreeMap<>();
  8.  
  9. String input= scanner.nextLine();
  10. int unliked=0;
  11. while (!input.equals("Stop")){
  12.  
  13. String[]complect=input.split("-");
  14. String command=complect[0];
  15.  
  16. switch (command){
  17. case"Like":
  18. String guest=complect[1];
  19. String meal=complect[2];
  20. if(!menu.containsKey(guest)){
  21. menu.put(guest,new ArrayList<String>());
  22. }else{
  23. List<String>eating=menu.get(guest);
  24. if(!eating.contains(meal)){
  25. eating.add(meal);
  26. }
  27. }
  28. break;
  29. case"Unlike":
  30. String Guest=complect[1];
  31. String Meal=complect[2];
  32. if(!menu.containsKey(Guest)){
  33. System.out.println(String.format("%s is not at the party.",Guest));
  34. }else{
  35. List<String> eatingU=menu.get(Guest);
  36. if(!eatingU.contains(Meal)){
  37. System.out.println(String.format("%s doesn't have the %s in his/her collection.",Guest,Meal));
  38. }else{
  39. unliked++;
  40. eatingU.remove(Meal);
  41. }
  42. }
  43. break;
  44. default:
  45. throw new IllegalStateException("wrong input");
  46. }
  47. input=scanner.nextLine();
  48. }
  49.  
  50.  
  51. menu.entrySet()
  52. .stream()
  53. .sorted((a,b)->b.getValue().size()-a.getValue().size())
  54. .forEach(h->{
  55. System.out.print(String.format("%s: ", h.getKey()));
  56. System.out.println(String.join(", ", h.getValue()));
  57. });
  58. System.out.println(String.format("Unliked meals: %d",unliked));
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement