Advertisement
gospod1978

List-Ex/House party

Oct 19th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace fundamental14
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.            
  12.             int numberOfCommands = int.Parse(Console.ReadLine());
  13.        
  14.             List<string> guests = new List<string>();
  15.            
  16.             for (int i = 0; i < numberOfCommands; i++)
  17.             {
  18.                 string[] arr = Console.ReadLine().Split();
  19.                 string name = arr[0];
  20.                 string element = arr[2];
  21.                
  22.                 if (element == "going!")
  23.                 {
  24.                     if (!guests.Contains(name))
  25.                     {
  26.                         guests.Add(name);
  27.                     }
  28.                     else
  29.                     {
  30.                         Console.WriteLine($"{name} is already in the list!");
  31.                     }
  32.                 }
  33.                 else
  34.                 {
  35.                     if (guests.Contains(name))
  36.                     {
  37.                         guests.Remove(name);
  38.                     }
  39.                     else
  40.                     {
  41.                         Console.WriteLine($"{name} is not in the list!");
  42.                     }
  43.                 }
  44.             }
  45.            
  46.             foreach (var guest in guests)
  47.             {
  48.             Console.WriteLine(guest);
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement