Advertisement
Guest User

Untitled

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