Advertisement
Guest User

Untitled

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