Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class lqlq {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, ArrayList>menu=new TreeMap<>();
- String input= scanner.nextLine();
- int unliked=0;
- while (!input.equals("Stop")){
- String[]complect=input.split("-");
- String command=complect[0];
- switch (command){
- case"Like":
- String guest=complect[1];
- String meal=complect[2];
- if(!menu.containsKey(guest)){
- menu.put(guest,new ArrayList<String>());
- }else{
- List<String>eating=menu.get(guest);
- if(!eating.contains(meal)){
- eating.add(meal);
- }
- }
- break;
- case"Unlike":
- String Guest=complect[1];
- String Meal=complect[2];
- if(!menu.containsKey(Guest)){
- System.out.println(String.format("%s is not at the party.",Guest));
- }else{
- List<String> eatingU=menu.get(Guest);
- if(!eatingU.contains(Meal)){
- System.out.println(String.format("%s doesn't have the %s in his/her collection.",Guest,Meal));
- }else{
- unliked++;
- eatingU.remove(Meal);
- }
- }
- break;
- default:
- throw new IllegalStateException("wrong input");
- }
- input=scanner.nextLine();
- }
- menu.entrySet()
- .stream()
- .sorted((a,b)->b.getValue().size()-a.getValue().size())
- .forEach(h->{
- System.out.print(String.format("%s: ", h.getKey()));
- System.out.println(String.join(", ", h.getValue()));
- });
- System.out.println(String.format("Unliked meals: %d",unliked));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement