Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ArraySlider
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = Console.ReadLine()
- .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- string[] command = Console.ReadLine().Split();
- int offset = int.Parse(command[0]);
- int operation = int.Parse(command[1]);
- int operand = int.Parse(command[2]);
- int currentPosition = 0;
- int remove = Math.Abs(offset) - currentPosition;
- if (offset < 0)
- {
- if (currentPosition - offset > 0)
- {
- currentPosition -= offset;
- }
- else if (currentPosition - offset < 0)
- {
- currentPosition = (array.Length - remove) - 1;
- }
- }
- else
- {
- currentPosition += offset % array.Length;
- }
- while (command[0] != "stop")
- {
- ExecuteCommands(array, operation, operand, currentPosition);
- command = Console.ReadLine().Split();
- operation = int.Parse(command[1]);
- operand = int.Parse(command[2]);
- offset = int.Parse(command[0]);
- }
- Console.WriteLine("[{0}]" , string.Join(", ",array));
- }
- static void ExecuteCommands(int[] array, int operation, int operand, int currentPostion)
- {
- switch (operation)
- {
- case '&':
- {
- array[currentPostion] &= operand;
- break;
- }
- case '|':
- {
- array[currentPostion] |= operand;
- break;
- }
- case '^':
- {
- array[currentPostion] ^= operand;
- break;
- }
- case '*':
- {
- array[currentPostion] *= operand;
- break;
- }
- case '/':
- {
- array[currentPostion] /= operand;
- break;
- }
- case '+':
- {
- array[currentPostion] += operand;
- break;
- }
- case '-':
- {
- array[currentPostion] -= operand;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement