Advertisement
andkamen

bla

Jul 6th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace test
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var numsList = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
  14.  
  15.             while (true)
  16.             {
  17.                 var line = Console.ReadLine();
  18.  
  19.                 if (line == "end")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.                 var commands = line.Split();
  25.                 var command = commands[0];
  26.  
  27.                 if (command == "reverse" || command == "sort")
  28.                 {
  29.                     var firstIndex = int.Parse(commands[2]);
  30.                     var secondIndex = int.Parse(commands[4]);
  31.  
  32.                     if (firstIndex < 0 || secondIndex < 0 || firstIndex >= numsList.Count || (firstIndex + secondIndex) >= numsList.Count)
  33.                     {
  34.                         Console.WriteLine("Invalid input parameters.");
  35.                         continue;
  36.                     }
  37.  
  38.                     var small = numsList.Skip(firstIndex).Take(secondIndex).ToList();
  39.  
  40.                     if (command == "reverse")
  41.                     {
  42.                         small.Reverse();
  43.                     }
  44.                     else if (command == "sort")
  45.                     {
  46.                         small.Sort();
  47.                     }
  48.                     numsList.RemoveRange(firstIndex, secondIndex);
  49.                     numsList.InsertRange(firstIndex, small);
  50.  
  51.                     //Console.WriteLine(string.Join(", ", small));
  52.                     //Console.WriteLine(secondIndex);
  53.                 }
  54.                 else
  55.                 {
  56.                     var countTimes = int.Parse(commands[1]);
  57.                     if (countTimes < 0)
  58.                     {
  59.                         Console.WriteLine("Invalid input parameters.");
  60.                     }
  61.                     if (command == "rollLeft")
  62.                     {
  63.  
  64.                         for (int i = 0; i < countTimes; i++)
  65.                         {
  66.                             var firstElement = numsList[0];
  67.                             numsList.Add(firstElement);
  68.                             numsList.RemoveAt(0);
  69.                         }
  70.                         //Console.WriteLine(string.Join(", ", firstElement));
  71.                     }
  72.                     else if (command == "rollRight")
  73.                     {
  74.                         for (int i = 0; i < countTimes; i++)
  75.                         {
  76.                             var lastElement = numsList[numsList.Count - 1];
  77.                             numsList.Insert(0, lastElement);
  78.                             numsList.RemoveAt(numsList.Count - 1);
  79.                         }
  80.                     }
  81.                 }
  82.  
  83.             }
  84.             Console.WriteLine("[" + string.Join(", ", numsList) + "]");
  85.  
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement