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;
- using System.Threading.Tasks;
- namespace _18_DebuggingCommands
- {
- class DebuggingCommands
- {
- private static int Size = int.Parse(Console.ReadLine());
- static void Main()
- {
- List<long> array = Console.ReadLine()
- .Split(' ')
- .Select(long.Parse)
- .ToList();
- while (true)
- {
- string[] command = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- if (command[0] == "stop")
- {
- break;
- }
- int[] arguments = new int[2];
- if (command[0] == "add" || command[0] == "subtract" || command[0] == "multiply")
- {
- arguments[0] = int.Parse(command[1]) - 1;
- arguments[1] = int.Parse(command[2]);
- }
- else
- {
- arguments[0] = 0;
- arguments[1] = 0;
- }
- array = PerformAction(array, command[0], arguments);
- Console.WriteLine(string.Join(" ", array));
- }
- }
- static List<long> PerformAction(List<long> arr, string action, int[] arguments)
- {
- int position = arguments[0];
- int value = arguments[1];
- switch (action)
- {
- case "multiply":
- arr[position] *= value;
- break;
- case "add":
- arr[position] += value;
- break;
- case "subtract":
- arr[position] -= value;
- break;
- case "lshift":
- arr = ArrayShiftLeft(arr);
- break;
- case "rshift":
- arr = ArrayShiftRight(arr);
- break;
- default:
- return arr;
- }
- return arr;
- }
- private static List<long> ArrayShiftRight(List<long> array)
- {
- Queue<long> shift = new Queue<long>();
- for (int i = Size - 1; i >= 0; i--)
- {
- shift.Enqueue(array[i]);
- }
- shift.Enqueue(shift.Dequeue());
- return new List<long>(shift.Reverse());
- }
- private static List<long> ArrayShiftLeft(List<long> array)
- {
- Queue<long> shift = new Queue<long>();
- for (int i = 0; i < Size; i++)
- {
- shift.Enqueue(array[i]);
- }
- shift.Enqueue(shift.Dequeue());
- return new List<long>(shift);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment