Advertisement
Guest User

Untitled

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