Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class CommandInterpreter
- {
- static void Main()
- {
- string[] input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
- string commandInput = Console.ReadLine();
- while (commandInput != "end")
- {
- int count = 0;
- int start = 0;
- string[] commandSplit = commandInput.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
- string command = commandSplit[0];
- if (commandSplit.Length == 5) //Проверява кой тип команда е въведена, за да приравни променливите.
- {
- start = int.Parse(commandSplit[2]);
- count = int.Parse(commandSplit[4]);
- if (count > input.Length - start)
- {
- Console.WriteLine("Invalid input parameters.");
- goto COMMAND;
- }
- }
- else
- {
- count = int.Parse(commandSplit[1]);
- if (count > input.Length)
- {
- count %= input.Length; //Oстават само меродавни отмествания, а тези които превъртат масива(count кратно на input.Length) се пренебрегват.
- }
- }
- if (start < 0 || start > input.Length - 1 || count < 0)
- {
- Console.WriteLine("Invalid input parameters.");
- }
- else
- {
- if (command == "reverse")
- {
- Array.Reverse(input, start, count);
- }
- else if (command == "sort")
- {
- Array.Sort(input, start, count);
- }
- else if (command == "rollRight") //Изпълнява се чрез копиране на части от input в друг масив(temp).
- {
- string[] temp = new string[input.Length];
- Array.Copy(input, 0, temp, count, temp.Length - count);
- Array.Copy(input, input.Length - count, temp, 0, count);
- input = temp;
- }
- else if (command == "rollLeft")// rollLeft- Изпълнява се чрез копиране на части от input в друг масив(temp).
- {
- string[] temp = new string[input.Length];
- Array.Copy(input, count, temp, 0, temp.Length - count);
- Array.Copy(input, 0, temp, temp.Length - count, count);
- input = temp;
- }
- }
- COMMAND: commandInput = Console.ReadLine(); //Тук слиза понякога и от 26-ред
- }
- Console.WriteLine("[" + String.Join(", ", input) + "]");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment