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;
- class Program
- {
- static void Main(string[] args)
- {
- List<string> nums = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- string command = "";
- while (true)
- {
- string[] input = Console.ReadLine().Split().ToArray();
- command = input[0];
- if (command == "end") break;
- else if (command == "reverse")
- {
- short start = short.Parse(input[2]);
- short count = short.Parse(input[4]);
- if (start < 0 || count < 0 || start >= nums.Count || count > nums.Count || start + count > nums.Count)
- {
- Console.WriteLine("Invalid input parameters.");
- continue;
- }
- string[] portion = new string[count];
- for (short i = 0; i < portion.Length; i++)
- {
- portion[i] = nums[start + i];
- }
- Array.Reverse(portion);
- for (short i = start; i < start + count; i++)
- {
- nums[i] = portion[i - start];
- }
- }
- else if (command == "sort")
- {
- short start = short.Parse(input[2]);
- short count = short.Parse(input[4]);
- if (start < 0 || count < 0 || start >= nums.Count || count > nums.Count || start + count > nums.Count)
- {
- Console.WriteLine("Invalid input parameters.");
- continue;
- }
- string[] portion = new string[count];
- for (short i = 0; i < portion.Length; i++)
- {
- portion[i] = nums[start + i];
- }
- portion = portion.OrderBy(x => x).ToArray();
- for (short i = start; i < start + count; i++)
- {
- nums[i] = portion[i - start];
- }
- }
- else if (command == "rollLeft")
- {
- int count = int.Parse(input[1]);
- if (count < 0)
- {
- Console.WriteLine("Invalid input parameters.");
- continue;
- }
- for (int i = 0; i < count % nums.Count; i++)
- {
- string temp = nums[0];
- nums.RemoveAt(0);
- nums.Add(temp);
- }
- }
- else if (command == "rollRight")
- {
- int count = int.Parse(input[1]);
- if (count < 0)
- {
- Console.WriteLine("Invalid input parameters.");
- continue;
- }
- for (int i = 0; i < count%nums.Count; i++)
- {
- string temp = nums[nums.Count - 1];
- nums.RemoveAt(nums.Count - 1);
- nums.Insert(0, temp);
- }
- }
- }
- Console.WriteLine("[" + string.Join(", ", nums) + "]");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement