desislava_topuzakova

02. Fitness Visitors

Apr 9th, 2022
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _03._Word_Game
  5. {
  6. internal class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string row = Console.ReadLine();
  11.  
  12. string [] arrayNames = row.Split(", ");
  13. List<string> names = new List<string>();
  14.  
  15. foreach (string name in arrayNames)
  16. {
  17. names.Add(name);
  18. }
  19.  
  20. String command = Console.ReadLine();
  21.  
  22. while (command != "END")
  23. {
  24. if (command == "Add visitor")
  25. {
  26. String newName = Console.ReadLine();
  27. names.Add(newName);
  28. }
  29. else if (command == "Add visitor on position")
  30. {
  31. String name = Console.ReadLine();
  32. int index = int.Parse(Console.ReadLine());
  33. names.Insert(index, name);
  34.  
  35. }
  36. else if (command == "Remove visitor on position")
  37. {
  38. int index = int.Parse(Console.ReadLine());
  39. names.RemoveAt(index);
  40.  
  41. }
  42. else if (command == "Remove last visitor")
  43. {
  44. names.RemoveAt(names.Count - 1);
  45. }
  46. else if (command == "Remove first visitor")
  47. {
  48. names.RemoveAt(0);
  49. }
  50.  
  51. command = Console.ReadLine();
  52. }
  53.  
  54.  
  55. Console.WriteLine(string.Join(", ", names);
  56. }
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment