Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ContactList
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> contacts = Console.ReadLine().Split().ToList();
  12.  
  13. while (true)
  14. {
  15. string[] command = Console.ReadLine().Split().ToArray();
  16.  
  17. if (command[0] == "Add")
  18. {
  19. int index = int.Parse(command[2]);
  20. if (contacts.Contains(command[1]))
  21. {
  22. contacts.Insert(index, command[1]);
  23. }
  24. else
  25. {
  26. contacts.Add(command[1]);
  27. }
  28. }
  29. else if (command[0] == "Remove")
  30. {
  31. int index = int.Parse(command[1]);
  32. if (index > contacts.Count || index < 0)
  33. {
  34. break;
  35. }
  36. else
  37. {
  38. contacts.RemoveAt(index);
  39. }
  40. }
  41. else if (command[0] == "Export")
  42. {
  43. int count = int.Parse(command[2]);
  44. int startIndex = int.Parse(command[1]);
  45. if (count > contacts.Count)
  46. {
  47. for (int i = startIndex; i < contacts.Count; i++)
  48. {
  49. Console.Write(contacts[i] + " ");
  50. }
  51. Console.WriteLine();
  52. }
  53. else
  54. {
  55. for (int i = startIndex; i < count; i++)
  56. {
  57. Console.Write(contacts[i] + " ");
  58. }
  59. Console.WriteLine();
  60. }
  61. }
  62. else if (command[0] == "Print")
  63. {
  64. if (command[1] == "Normal")
  65. {
  66. Console.WriteLine("Contacts: " + string.Join(" ", contacts));
  67. }
  68. else if (command[1] == "Reversed")
  69. {
  70. contacts.Reverse();
  71. Console.WriteLine("Contacts: " + string.Join(" ", contacts));
  72. }
  73. }
  74. if (command[0] == "Print")
  75. {
  76. break;
  77. }
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement