Advertisement
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 CommandInterpreter
- {
- class CommandInterpreter
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(s => s.Trim()).ToArray();
- var modifiedList = new List<string>(input).ToList();
- int lenght = modifiedList.Count - 1;
- var command = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(s => s.Trim()).ToArray();
- while (command[0] != "end")
- {
- if (command[0] == "reverse" || command[0] == "sort")
- {
- int start = int.Parse(command[2]);
- int count = int.Parse(command[4]);
- if ((start < 0) || (count < 1) || ((start + count) > input.Length) || (start > input.Length - 1)
- || (count > input.Length))
- {
- Console.WriteLine("Invalid input parameters.");
- goto END;
- }
- if (command[0] == "reverse")
- {
- int a = 0;
- for (int i = start; i < (start + count); i++)
- {
- modifiedList[i] = input[(count + start - 1) - a];
- a++;
- }
- }
- else if (command[0] == "sort")
- {
- List<string> part = modifiedList.GetRange(start, count);
- part = part.OrderByDescending(a => a).ToList();
- modifiedList.RemoveRange(start, count);
- int b = 0;
- for (int i = start; i < (start + count); i++)
- {
- modifiedList.Insert(start, part[b]);
- b++;
- }
- }
- }
- else if (command[0] == "rollLeft")
- {
- long countLeftRoll = long.Parse(command[1]);
- for (long i = 0; i < countLeftRoll; i++)
- {
- modifiedList.Add(modifiedList[0]);
- modifiedList.RemoveAt(0);
- }
- }
- else if (command[0] == "rollRight")
- {
- long countRightRoll = long.Parse(command[1]);
- for (long i = 0; i < countRightRoll; i++)
- {
- modifiedList.Insert(0, modifiedList[lenght]);
- modifiedList.RemoveAt(lenght + 1);
- }
- }
- END:
- command = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(s => s.Trim()).ToArray();
- }
- Console.WriteLine("[" + String.Join(", ", modifiedList) + "]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement