Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Dictionary___Nikulden_s_meals
- {
- class Program
- {
- static void Main(string[] args)
- {
- var guestList = new Dictionary<string, List<string>>();
- int count = 0;
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Stop")
- {
- break;
- }
- string[] tokens = input.Split("-");
- string command = tokens[0];
- string guest = tokens[1];
- string meal = tokens[2];
- switch (command)
- {
- case "Like":
- if (!guestList.ContainsKey(guest))
- {
- guestList.Add(guest, new List<string>());
- }
- if (!guestList[guest].Contains(meal))
- {
- guestList[guest].Add(meal);
- }
- break;
- case "Unlike":
- if (!guestList.ContainsKey(guest))
- {
- Console.WriteLine($"{guest} is not at the party.");
- }
- else if (guestList[guest].Contains(meal))
- {
- Console.WriteLine($"{guest} doesn't like the {meal}.");
- guestList[guest].Remove(meal);
- count++;
- }
- else
- {
- Console.WriteLine($"{guest} doesn't have the {meal} in his/her collection.");
- }
- break;
- }
- }
- guestList = guestList.OrderByDescending(x => x.Value.Count)
- .ThenBy(x => x.Key)
- .ToDictionary(x => x.Key, y => y.Value);
- foreach (var kvp in guestList)
- {
- Console.Write($"{kvp.Key}: ");
- Console.WriteLine(string.Join(", ", kvp.Value));
- }
- Console.WriteLine($"Unliked meals: {count}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement