Advertisement
Guest User

Untitled

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