Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class SequenceOfCommands_broken
- {
- private const char ArgumentsDelimiter = ' ';
- public static void Main()
- {
- int sizeOfArray = int.Parse(Console.ReadLine());
- long[] array = Console.ReadLine()
- .Split(ArgumentsDelimiter)
- .Select(long.Parse)
- .ToArray();
- string[] command = Console.ReadLine().Split(' ');
- while (!command.Equals("stop"))
- {
- int[] args = new int[2];
- if (command.Equals("add") ||
- command.Equals("substract") ||
- command.Equals("multiply"))
- {
- args[0] = int.Parse(command[1]);
- args[1] = int.Parse(command[2]);
- }
- PerformAction(array, command[0], args);
- PrintArray(array);
- Console.WriteLine();
- command = Console.ReadLine().Split(' ');
- }
- }
- static void PerformAction(long[] array, string action, int[] args)
- {
- int pos = args[0];
- int value = args[1];
- switch (action)
- {
- case "multiply":
- array[pos - 1] *= value;
- break;
- case "add":
- array[pos - 1] += value;
- break;
- case "subtract":
- array[pos - 1] -= value;
- break;
- case "lshift":
- ArrayShiftLeft(array);
- break;
- case "rshift":
- ArrayShiftRight(array);
- break;
- }
- }
- private static void ArrayShiftRight(long[] array)
- {
- long gg = array[array.Length - 1];
- for (int i = array.Length - 1; i >= 1; i--)
- {
- array[i] = array[i - 1];
- }
- array[0] = gg;
- }
- private static void ArrayShiftLeft(long[] array)
- {
- long gg = array[0];
- for (int i = 0; i < array.Length - 1; i++)
- {
- array[i] = array[i + 1];
- }
- array[array.Length - 1] = gg;
- }
- private static void PrintArray(long[] array)
- {
- foreach (long arrays in array)
- {
- Console.Write(arrays + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement