Guest User

Untitled

a guest
Oct 28th, 2019
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._03._ContactList
  6. {
  7. class ContactList
  8. {
  9. static void Main()
  10. {
  11. List<string> contacts = Console.ReadLine()
  12. .Split(" ")
  13. .ToList();
  14.  
  15. List<string> exportPrint = new List<string>();
  16.  
  17. while (true)
  18. {
  19. string input = Console.ReadLine();
  20. string[] splitedInput = input.Split(" ");
  21. string command = splitedInput[0];
  22.  
  23. switch (command)
  24. {
  25. case "Add":
  26.  
  27. string contact = splitedInput[1];
  28. int index = int.Parse(splitedInput[2]);
  29.  
  30. if (!contacts.Contains(contact))
  31. {
  32. contacts.Add(contact);
  33. }
  34.  
  35. else
  36. {
  37. if (index >= 0 && index < contacts.Count)
  38. {
  39. contacts.Insert(index, contact);
  40. }
  41. }
  42.  
  43.  
  44. break;
  45.  
  46. case "Remove":
  47.  
  48. index = int.Parse(splitedInput[1]);
  49.  
  50. if (index >= 0 && index < contacts.Count)
  51. {
  52. contacts.RemoveAt(index);
  53. }
  54.  
  55. break;
  56.  
  57. case "Export":
  58.  
  59. int startIndex = int.Parse(splitedInput[1]);
  60. int count = int.Parse(splitedInput[2]);
  61.  
  62. if (startIndex >= 0 && startIndex < contacts.Count() && count > 0)
  63. {
  64. if (count >= contacts.Count || count <= 0)
  65. {
  66. count = contacts.Count;
  67. }
  68.  
  69. for (int i = startIndex; i < count; i++)
  70. {
  71. exportPrint.Add(contacts[i]);
  72. }
  73.  
  74. Console.WriteLine(string.Join(" ", exportPrint));
  75. exportPrint.Clear();
  76. }
  77.  
  78. break;
  79.  
  80. case "Print":
  81.  
  82. string secondCommand = splitedInput[1];
  83.  
  84. if (secondCommand == "Normal")
  85. {
  86. Console.WriteLine($"Contacts: {string.Join(" ", contacts)}");
  87.  
  88. return;
  89. }
  90.  
  91. else if (secondCommand == "Reversed")
  92. {
  93. contacts.Reverse();
  94.  
  95. Console.WriteLine($"Contacts: {string.Join(" ", contacts)}");
  96.  
  97. return;
  98. }
  99.  
  100.  
  101. break;
  102. }
  103.  
  104. }
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment