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