Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _02.Command_Interpreter
  8. {
  9. class CommandInterpreter
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<string> nums = Console.ReadLine().Split().ToList();
  14.  
  15. string[] command = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  16.  
  17. int start = 0;
  18. int count = 0;
  19.  
  20. while (!command[0].Equals("end"))
  21. {
  22. List<string> currList = new List<string>();
  23.  
  24. switch (command[0])
  25. {
  26. case "reverse":
  27. start = int.Parse(command[2]);
  28. count = int.Parse(command[4]);
  29.  
  30. if (start < 0 || count < 0 || (start + count) >= nums.Count)
  31. {
  32. Console.WriteLine("Invalid input parameters.");
  33. break;
  34. }
  35.  
  36. currList = nums.Skip(start).Take(count).Reverse().ToList();
  37. nums.RemoveRange(start, count);
  38. nums.InsertRange(start, currList);
  39.  
  40. break;
  41. case "sort":
  42.  
  43. start = int.Parse(command[2]);
  44. count = int.Parse(command[4]);
  45.  
  46. if (start < 0 || count < 0 || (start + count) >= nums.Count)
  47. {
  48. Console.WriteLine("Invalid input parameters.");
  49. break;
  50. }
  51.  
  52. currList = nums.Skip(start).Take(count).OrderBy(x => x).ToList();
  53.  
  54. nums.RemoveRange(start, count);
  55. nums.InsertRange(start, currList);
  56.  
  57. break;
  58. case "rollLeft":
  59.  
  60. count = int.Parse(command[1]);
  61.  
  62. if (count < 0)
  63. {
  64. Console.WriteLine("Invalid input parameters.");
  65. break;
  66. }
  67.  
  68. for (int i = 0; i < (count % nums.Count); i++)
  69. {
  70. var element = nums[0];
  71.  
  72. nums.RemoveAt(0);
  73. nums.Add(element);
  74. }
  75.  
  76. break;
  77. case "rollRight":
  78.  
  79. count = int.Parse(command[1]);
  80.  
  81. if (count < 0)
  82. {
  83. Console.WriteLine("Invalid input parameters.");
  84. break;
  85. }
  86.  
  87. for (int i = 0; i < (count % nums.Count); i++)
  88. {
  89. var temp = nums[nums.Count - 1];
  90.  
  91. nums.RemoveAt(nums.Count - 1);
  92. nums.Insert(0, temp);
  93. }
  94. break;
  95. default:
  96. break;
  97. }
  98.  
  99.  
  100. command = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  101. }
  102.  
  103. Console.WriteLine("[{0}]", string.Join(", ", nums));
  104.  
  105.  
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement