Advertisement
Guest User

Untitled

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