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