Advertisement
AngelVasilev

SoftUni Fundamentals - Nikulden's meals

Apr 3rd, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Dictionary___Nikulden_s_meals
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var guestList = new Dictionary<string, List<string>>();
  12.             int count = 0;
  13.  
  14.             while (true)
  15.             {
  16.                 string input = Console.ReadLine();
  17.                 if (input == "Stop")
  18.                 {
  19.                     break;
  20.                 }
  21.  
  22.                 string[] tokens = input.Split("-");
  23.                 string command = tokens[0];
  24.                 string guest = tokens[1];
  25.                 string meal = tokens[2];
  26.  
  27.                 switch (command)
  28.                 {
  29.                     case "Like":
  30.                         if (!guestList.ContainsKey(guest))
  31.                         {
  32.                             guestList.Add(guest, new List<string>());
  33.                         }
  34.                         if (!guestList[guest].Contains(meal))
  35.                         {
  36.                             guestList[guest].Add(meal);
  37.                         }
  38.                         break;
  39.  
  40.                     case "Unlike":
  41.                         if (!guestList.ContainsKey(guest))
  42.                         {
  43.                             Console.WriteLine($"{guest} is not at the party.");
  44.                         }
  45.                         else if (guestList[guest].Contains(meal))
  46.                         {
  47.                             Console.WriteLine($"{guest} doesn't like the {meal}.");
  48.                             guestList[guest].Remove(meal);
  49.                             count++;
  50.                         }
  51.                         else
  52.                         {
  53.                             Console.WriteLine($"{guest} doesn't have the {meal} in his/her collection.");
  54.                         }
  55.                         break;
  56.                 }
  57.             }
  58.  
  59.             guestList = guestList.OrderByDescending(x => x.Value.Count)
  60.                 .ThenBy(x => x.Key)
  61.                 .ToDictionary(x => x.Key, y => y.Value);
  62.  
  63.             foreach (var kvp in guestList)
  64.             {
  65.                 Console.Write($"{kvp.Key}: ");
  66.                 Console.WriteLine(string.Join(", ", kvp.Value));
  67.             }
  68.  
  69.             Console.WriteLine($"Unliked meals: {count}");
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement