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