Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Exam_Preparation_III
- {
- class Program
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine();
- List<string> inputArray = input.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries).ToList();
- string inputCommand = Console.ReadLine();
- while (inputCommand != "end")
- {
- List<string> command = inputCommand.Split(' ').ToList();
- switch (command[0])
- {
- case "reverse":
- int start = int.Parse(command[2]);
- int count = int.Parse(command[4]);
- if (start >= inputArray.Count || count > inputArray.Count - start || start < 0 || count < 0)
- {
- Console.WriteLine("Invalid input parameters.");
- }
- else
- {
- inputArray.Reverse(start, count);
- }
- break;
- case "sort":
- start = int.Parse(command[2]);
- count = int.Parse(command[4]);
- if (start >= inputArray.Count || count > inputArray.Count - start || start < 0 || count < 0)
- {
- Console.WriteLine("Invalid input parameters.");
- }
- else
- {
- inputArray.Sort(start, count, StringComparer.InvariantCulture);
- }
- break;
- case "rollLeft":
- count = int.Parse(command[1]);
- if (count >= 0)
- {
- for (int i = 0; i < count % inputArray.Count; i++)
- {
- string firstElement = inputArray[0];
- for (int j = 0; j < inputArray.Count - 1; j++)
- {
- inputArray[j] = inputArray[j + 1];
- }
- inputArray[inputArray.Count - 1] = firstElement;
- }
- }
- else
- {
- Console.WriteLine("Invalid input parameters.");
- }
- break;
- case "rollRight":
- count = int.Parse(command[1]);
- if (count >= 0)
- {
- for (int i = 0; i < count % inputArray.Count; i++)
- {
- string lastElement = inputArray[inputArray.Count - 1];
- for (int j = inputArray.Count - 1; j > 0; j--)
- {
- inputArray[j] = inputArray[j - 1];
- }
- inputArray[0] = lastElement;
- }
- }
- else
- {
- Console.WriteLine("Invalid input parameters.");
- }
- break;
- }
- inputCommand = Console.ReadLine();
- }
- Console.WriteLine("[" + (string.Join(", ", inputArray)) + "]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement