Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7. namespace ArraySlider
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] array = Console.ReadLine()
  14. .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
  15. .Select(int.Parse)
  16. .ToArray();
  17. string[] command = Console.ReadLine().Split();
  18. int offset = int.Parse(command[0]);
  19. int operation = int.Parse(command[1]);
  20. int operand = int.Parse(command[2]);
  21. int currentPosition = 0;
  22. int remove = Math.Abs(offset) - currentPosition;
  23. if (offset < 0)
  24. {
  25. if (currentPosition - offset > 0)
  26. {
  27. currentPosition -= offset;
  28. }
  29. else if (currentPosition - offset < 0)
  30. {
  31. currentPosition = (array.Length - remove) - 1;
  32. }
  33.  
  34. }
  35. else
  36. {
  37. currentPosition += offset % array.Length;
  38. }
  39.  
  40. while (command[0] != "stop")
  41. {
  42. ExecuteCommands(array, operation, operand, currentPosition);
  43.  
  44.  
  45. command = Console.ReadLine().Split();
  46. operation = int.Parse(command[1]);
  47. operand = int.Parse(command[2]);
  48. offset = int.Parse(command[0]);
  49. }
  50. Console.WriteLine("[{0}]" , string.Join(", ",array));
  51. }
  52. static void ExecuteCommands(int[] array, int operation, int operand, int currentPostion)
  53. {
  54. switch (operation)
  55. {
  56. case '&':
  57. {
  58. array[currentPostion] &= operand;
  59. break;
  60. }
  61. case '|':
  62. {
  63. array[currentPostion] |= operand;
  64. break;
  65. }
  66. case '^':
  67. {
  68. array[currentPostion] ^= operand;
  69. break;
  70. }
  71. case '*':
  72. {
  73. array[currentPostion] *= operand;
  74. break;
  75. }
  76. case '/':
  77. {
  78. array[currentPostion] /= operand;
  79. break;
  80. }
  81. case '+':
  82. {
  83. array[currentPostion] += operand;
  84. break;
  85. }
  86. case '-':
  87. {
  88. array[currentPostion] -= operand;
  89. break;
  90. }
  91.  
  92. }
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement