Advertisement
Guest User

Untitled

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