Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Runtime.InteropServices;
- class Program
- {
- static void Main()
- {
- int[] arr = Console.ReadLine()
- .Split(' ')
- .Select(int.Parse)
- .ToArray();
- string command = Console.ReadLine();
- int currentPosition = 0;
- int arrHelper = currentPosition;
- string operations = "&|^+-*/";
- while (command != "stop")
- {
- var line = command.Split(' ');
- int offset = int.Parse(line[0]);
- string symbol = line[1];
- int operand = int.Parse(line[2]);
- arrHelper += offset; //0 + 2
- /*
- 1 2 3 4 5
- 2 * 2 position = 2
- 2 / 2 position = 4
- 1 – 2 position = 0
- -2 & 1 position = 3
- stop
- */
- if (arrHelper >= arr.Length && offset >= 0) //2 > 5
- {
- currentPosition = arrHelper - arr.Length;
- GetValue(symbol, arr, currentPosition, operand);
- if (arr[currentPosition] < 0)
- {
- arr[currentPosition] = 0;
- }
- arrHelper = currentPosition;
- }
- else if (arrHelper < 0 && offset < 0)
- {
- currentPosition = arrHelper + arr.Length;
- GetValue(symbol, arr, currentPosition, operand);
- if (arr[currentPosition] < 0)
- {
- arr[currentPosition] = 0;
- }
- arrHelper = currentPosition;
- }
- else
- {
- currentPosition = arrHelper;
- GetValue(symbol, arr, currentPosition, operand);
- if (arr[currentPosition] < 0)
- {
- arr[currentPosition] = 0;
- }
- arrHelper = currentPosition;
- }
- command = Console.ReadLine();
- }
- Console.Write("[");
- Console.Write(string.Join(", ", arr));
- Console.Write("]");
- Console.WriteLine( );
- }
- private static void GetValue(string symbol, int[] arr, int currentPosition, int operand)
- {
- switch (symbol)
- {
- case "&":
- arr[currentPosition] &= operand;
- break;
- case "|":
- arr[currentPosition] |= operand;
- break;
- case "^":
- arr[currentPosition] ^= operand;
- break;
- case "+":
- arr[currentPosition] += operand;
- break;
- case "-":
- arr[currentPosition] -= operand;
- break;
- case "*":
- arr[currentPosition] *= operand;
- break;
- case "/":
- arr[currentPosition] /= operand;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement