Advertisement
Guest User

Untitled

a guest
Jan 26th, 2019
1,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.ListOperations
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> numbers = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. while (true)
  17. {
  18. string[] input = Console.ReadLine().Split();
  19. string command = input[0];
  20.  
  21. if (command == "End")
  22. {
  23. break;
  24. }
  25.  
  26. if (command == "Add")
  27. {
  28. int number = int.Parse(input[1]);
  29. numbers.Add(number);
  30. }
  31. else if (command == "Insert")
  32. {
  33. int numberToInsert = int.Parse(input[1]);
  34. int index = int.Parse(input[2]);
  35.  
  36. numbers.Insert(index, numberToInsert);
  37.  
  38. if (index < 0 || index > numbers.Count)
  39. {
  40. Console.WriteLine("Invalid index");
  41. }
  42. }
  43. else if (command == "Remove")
  44. {
  45. int index = int.Parse(input[1]);
  46. if (index < 0 || index > numbers.Count)
  47. {
  48. Console.WriteLine("Invalid index");
  49. continue;
  50. }
  51. else
  52. {
  53.  
  54. numbers.RemoveAt(index);
  55. }
  56.  
  57. }
  58. else if (command == "Shift")
  59. {
  60. string direction = input[1];
  61. int rotations = int.Parse(input[2]);
  62.  
  63. if (direction == "left")
  64. {
  65. for (int i = 0; i < rotations % numbers.Count; i++)
  66. {
  67. int firstNum = numbers[0];
  68. numbers.Add(firstNum);
  69. numbers.RemoveAt(0);
  70. }
  71. }
  72. else
  73. {
  74. for (int i = 0; i < rotations % numbers.Count; i++)
  75. {
  76. int lastNum = numbers[numbers.Count - 1];
  77. numbers.Insert(0, lastNum);
  78. numbers.RemoveAt(numbers.Count - 1);
  79. }
  80. }
  81. }
  82. }
  83. Console.WriteLine(string.Join(" ", numbers));
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement