Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ExamPreparation
- {
- class Startup
- {
- private const char ArgumentsDelimiter = ' ';
- static void Main()
- {
- int sizeOfArray = int.Parse(Console.ReadLine());
- long[] array = Console.ReadLine()
- .Split(ArgumentsDelimiter)
- .Select(long.Parse)
- .ToArray();
- string command = Console.ReadLine();
- while (!command.Equals("stop"))
- {
- string[] tokens = command.Split(ArgumentsDelimiter);
- int index = 0, value = 0;
- if (tokens.Length > 1)
- {
- index = int.Parse(tokens[1]);
- value = int.Parse(tokens[2]);
- index -= 1;
- }
- switch (tokens[0])
- {
- case "multiply":
- array[index] *= value;
- break;
- case "add":
- array[index] += value;
- break;
- case "subtract":
- array[index] -= value;
- break;
- case "lshift":
- ShiftLeft(ref array);
- break;
- case "rshift":
- ShiftRight(ref array);
- break;
- }
- Print(array);
- command = Console.ReadLine();
- }
- }
- private static void ShiftRight(ref long[] array)
- {
- var firstHalf = array.Reverse().Take(1);
- var secondHalf = array.Reverse().Skip(1).Reverse();
- array = firstHalf.Concat(secondHalf).ToArray();
- }
- private static void ShiftLeft(ref long[] array)
- {
- var firsHalf = array.Skip(1);
- var secondHalf = array.Take(1);
- array = firsHalf.Concat(secondHalf).ToArray();
- }
- private static void Print(long[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment