Guest User

Untitled

a guest
Apr 18th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 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 _3_02.CommandInterpreter
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var stringArr = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  14.  
  15. var command = Console.ReadLine();
  16.  
  17. while(command != "end")
  18. {
  19. var splitted = command.Split();
  20.  
  21. if (splitted[0] == "reverse")
  22. {
  23. var start = int.Parse(splitted[2]);
  24. var count = int.Parse(splitted[4]);
  25. if (start < stringArr.Count &&start>= 0 && (count + start) <= stringArr.Count &&(count+start)>=0)
  26. stringArr.Reverse(start, count);
  27.  
  28. else
  29. Console.WriteLine("Invalid input parameters.");
  30.  
  31. }
  32. else if (splitted[0] == "sort")
  33. {
  34. var start = int.Parse(splitted[2]);
  35. var count = int.Parse(splitted[4]);
  36.  
  37. if (start < stringArr.Count && start >=0 &&(count + start) <= stringArr.Count && (count +start) >=0)
  38. stringArr.Sort(start, count, null);
  39.  
  40. else
  41. Console.WriteLine("Invalid input parameters.");
  42.  
  43. }
  44. else if (splitted[0] == "rollLeft")
  45. {
  46. var count = int.Parse(splitted[1]);
  47. count %= stringArr.Count;
  48. for (int i = 0; i < count; i++)
  49. {
  50. var currNum = stringArr[0];
  51. stringArr.RemoveAt(0);
  52. stringArr.Add(currNum);
  53.  
  54. }
  55. }
  56. else if (splitted[0] == "rollRight")
  57. {
  58. var count = int.Parse(splitted[1]);
  59. count %= stringArr.Count;
  60. for (int i = 0; i < count; i++)
  61. {
  62. var currNum = stringArr[stringArr.Count - 1];
  63. stringArr.RemoveAt(stringArr.Count - 1);
  64. stringArr.Insert(0, currNum);
  65. }
  66. }
  67.  
  68.  
  69. command = Console.ReadLine();
  70. }
  71. Console.WriteLine("["+String.Join(", ", stringArr) +"]");
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment