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 test
- {
- class Program
- {
- static void Main(string[] args)
- {
- var numsList = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
- while (true)
- {
- var line = Console.ReadLine();
- if (line == "end")
- {
- break;
- }
- var commands = line.Split();
- var command = commands[0];
- if (command == "reverse" || command == "sort")
- {
- var firstIndex = int.Parse(commands[2]);
- var secondIndex = int.Parse(commands[4]);
- if (firstIndex < 0 || secondIndex < 0 || firstIndex >= numsList.Count || (firstIndex + secondIndex) >= numsList.Count)
- {
- Console.WriteLine("Invalid input parameters.");
- continue;
- }
- var small = numsList.Skip(firstIndex).Take(secondIndex).ToList();
- if (command == "reverse")
- {
- small.Reverse();
- }
- else if (command == "sort")
- {
- small.Sort();
- }
- numsList.RemoveRange(firstIndex, secondIndex);
- numsList.InsertRange(firstIndex, small);
- //Console.WriteLine(string.Join(", ", small));
- //Console.WriteLine(secondIndex);
- }
- else
- {
- var countTimes = int.Parse(commands[1]);
- if (countTimes < 0)
- {
- Console.WriteLine("Invalid input parameters.");
- }
- if (command == "rollLeft")
- {
- for (int i = 0; i < countTimes; i++)
- {
- var firstElement = numsList[0];
- numsList.Add(firstElement);
- numsList.RemoveAt(0);
- }
- //Console.WriteLine(string.Join(", ", firstElement));
- }
- else if (command == "rollRight")
- {
- for (int i = 0; i < countTimes; i++)
- {
- var lastElement = numsList[numsList.Count - 1];
- numsList.Insert(0, lastElement);
- numsList.RemoveAt(numsList.Count - 1);
- }
- }
- }
- }
- Console.WriteLine("[" + string.Join(", ", numsList) + "]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement