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 _02.Command_Interpreter
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> inputElement = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- List<string> tempList = new List<string>();
- List<string> commands = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- while (commands[0] != "end")
- {
- if (commands[0] == "reverse")
- {
- int startIndex = int.Parse(commands[2]);
- int countElement = int.Parse(commands[4]);
- if (startIndex < 0 || countElement < 0 || startIndex + countElement > inputElement.Count - 1)
- {
- Console.WriteLine("Invalid input parameters.");
- }
- else
- {
- for (int i = startIndex; i < startIndex + countElement; i++)
- {
- tempList.Add(inputElement[i]);
- }
- tempList.Reverse();
- for (int i = 0; i < countElement; i++)
- {
- inputElement[i + startIndex] = tempList[i];
- }
- }
- }
- else if (commands[0] == "rollLeft")
- {
- int count = int.Parse(commands[1]);
- if (count >= 0)
- {
- for (int i = 0; i < count; i++)
- {
- inputElement.Add(inputElement[0]);
- inputElement.RemoveAt(0);
- }
- }
- else
- {
- Console.WriteLine("Invalid input parameters.");
- }
- }
- else if (commands[0] == "rollRight")
- {
- int count = int.Parse(commands[1]);
- if (count >= 0)
- {
- for (int i = 0; i < count; i++)
- {
- inputElement.Insert(0, inputElement[inputElement.Count - 1]);
- inputElement.RemoveAt(inputElement.Count - 1);
- }
- }
- else
- {
- Console.WriteLine("Invalid input parameters.");
- }
- }
- else if (commands[0] == "sort")
- {
- tempList = new List<string>();
- int index = int.Parse(commands[2]);
- int count = int.Parse(commands[4]);
- if (index < 0 || count < 0 || index + count > inputElement.Count - 1)
- {
- Console.WriteLine("Invalid input parameters.");
- }
- else
- {
- for (int i = index; i < index + count; i++)
- {
- tempList.Add(inputElement[i]);
- }
- tempList.Sort();
- for (int i = 0; i < count; i++)
- {
- inputElement[i + index] = tempList[i];
- }
- }
- }
- commands = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- }
- Console.WriteLine("[" + string.Join(", ", inputElement) + "]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment