Teo_Yanchev

ListsExercise - 3.HouseParty - C# Fundamentals

Sep 19th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _3.HouseParty
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. int numberOfCommands = int.Parse(Console.ReadLine());
  12. List<string> guests = new List<string>();
  13.  
  14. for (int i = 0; i < numberOfCommands; i++)
  15. {
  16. List<string> nameGuests = Console.ReadLine()
  17. .Split()
  18. .ToList();
  19.  
  20. if (nameGuests[2] == "not")
  21. {
  22. if (guests.Contains(nameGuests[0]))
  23. {
  24. guests.Remove(nameGuests[0]);
  25. continue;
  26. }
  27.  
  28. else
  29. {
  30. Console.WriteLine($"{nameGuests[0]} is not in the list!");
  31. continue;
  32. }
  33.  
  34. }
  35.  
  36. else
  37. {
  38. if (guests.Contains(nameGuests[0]))
  39. {
  40. Console.WriteLine($"{nameGuests[0]} is already in the list!");
  41. continue;
  42. }
  43.  
  44. else
  45. {
  46. guests.Add(nameGuests[0]);
  47. }
  48. }
  49. }
  50.  
  51. Console.WriteLine(string.Join($"\n", guests));
  52. }
  53. }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment