Advertisement
North_Point

05. String Commander

Aug 3rd, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 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 _05.String_Commander
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var input = Console.ReadLine();
  14.             var result = "";
  15.             while (true)
  16.             {
  17.                 var commands = Console.ReadLine().Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries);
  18.  
  19.                 if (commands[0] == "end")
  20.                 {
  21.                     break;
  22.                 }
  23.                 if (commands[0] == "Left")
  24.                 {
  25.                     for (int i = 0; i < int.Parse(commands[1]); i++)
  26.                     {
  27.                         result = input.Remove(0, 1).Insert(input.Length - 1, input.First().ToString());
  28.                         input = result;
  29.                     }
  30.                 }
  31.                  else if (commands[0] == "Delete")
  32.                 {
  33.                     result = input.Remove(int.Parse(commands[1]),int.Parse(commands[2]) + 1);
  34.                     input = result;
  35.                 }
  36.                 else if (commands[0] == "Right")
  37.                 {
  38.                     for (int i = 0; i < int.Parse(commands[1]); i++)
  39.                     {
  40.                         result = input.Remove(input.Length - 1, 1).Insert(0, input.Last().ToString());
  41.                         input = result;
  42.                     }
  43.                 }
  44.                 else if (commands[0] == "Insert")
  45.                 {
  46.                     result = input.Insert(int.Parse(commands[1]), commands[2]);
  47.                     input = result;
  48.                 }
  49.             }
  50.             Console.WriteLine(input);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement