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 _02.Command_Interpreter
- {
- class CommandInterpreter
- {
- static void Main(string[] args)
- {
- List<string> nums = Console.ReadLine().Split().ToList();
- string[] command = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- int start = 0;
- int count = 0;
- while (!command[0].Equals("end"))
- {
- List<string> currList = new List<string>();
- switch (command[0])
- {
- case "reverse":
- start = int.Parse(command[2]);
- count = int.Parse(command[4]);
- if (start < 0 || count < 0 || (start + count) >= nums.Count)
- {
- Console.WriteLine("Invalid input parameters.");
- break;
- }
- currList = nums.Skip(start).Take(count).Reverse().ToList();
- nums.RemoveRange(start, count);
- nums.InsertRange(start, currList);
- break;
- case "sort":
- start = int.Parse(command[2]);
- count = int.Parse(command[4]);
- if (start < 0 || count < 0 || (start + count) >= nums.Count)
- {
- Console.WriteLine("Invalid input parameters.");
- break;
- }
- currList = nums.Skip(start).Take(count).OrderBy(x => x).ToList();
- nums.RemoveRange(start, count);
- nums.InsertRange(start, currList);
- break;
- case "rollLeft":
- count = int.Parse(command[1]);
- if (count < 0)
- {
- Console.WriteLine("Invalid input parameters.");
- break;
- }
- for (int i = 0; i < (count % nums.Count); i++)
- {
- var element = nums[0];
- nums.RemoveAt(0);
- nums.Add(element);
- }
- break;
- case "rollRight":
- count = int.Parse(command[1]);
- if (count < 0)
- {
- Console.WriteLine("Invalid input parameters.");
- break;
- }
- for (int i = 0; i < (count % nums.Count); i++)
- {
- var temp = nums[nums.Count - 1];
- nums.RemoveAt(nums.Count - 1);
- nums.Insert(0, temp);
- }
- break;
- default:
- break;
- }
- command = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- }
- Console.WriteLine("[{0}]", string.Join(", ", nums));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement