Advertisement
Guest User

meals

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