Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp33
- {
- class Program
- {
- static void Main(string[] args) {
- Dictionary<string, List<string>> guests = new Dictionary<string, List<string>>();
- int unliked = 0;
- string[] cmd;
- while ((cmd = Console.ReadLine().Split('-'))[0] != "Stop") {
- string guest = cmd[1], meal = cmd[2];
- if (cmd[0] == "Like") {
- if (!guests.ContainsKey(guest)) {
- guests[guest] = new List<string> { meal };
- } else if (guests[guest].IndexOf(meal) == -1) {
- guests[guest].Add(meal);
- }
- } else { // Unlike
- int index;
- if (!guests.ContainsKey(guest)) {
- Console.WriteLine($"{guest} is not at the party.");
- } else if((index = guests[guest].IndexOf(meal)) == -1) {
- Console.WriteLine($"{guest} doesn't have the {meal} in his/her collection.");
- } else {
- guests[guest].RemoveAt(index);
- unliked++;
- Console.WriteLine($"{guest} doesn't like the {meal}.");
- }
- }
- }
- guests
- .OrderByDescending(kvp => kvp.Value.Count)
- .ThenBy(kvp => kvp.Key)
- .ToList()
- .ForEach(kvp => {
- Console.WriteLine($"{kvp.Key}: {string.Join(", ", kvp.Value)}".Trim());
- });
- Console.WriteLine($"Unliked meals: {unliked}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment