Advertisement
YavorGrancharov

String_Commander(helped)

Aug 5th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 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 String_Commander
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             string commands = Console.ReadLine();
  15.  
  16.             while (commands != "end")
  17.             {
  18.                 string[] tokens = commands.Split(' ');
  19.                 string command = tokens[0];
  20.                 switch (command)
  21.                 {
  22.                     case "Left":
  23.                         int left = int.Parse(tokens[1]);
  24.                         left %= input.Length;
  25.                         input = input.Substring(left) + input.Substring(0, left);
  26.                         break;
  27.                     case "Right":
  28.                         int right = int.Parse(tokens[1]);
  29.                         right %= input.Length;
  30.                         input = input.Substring(input.Length - right) + input.Substring(0, input.Length - right);
  31.                         break;
  32.                     case "Insert":
  33.                         int index = int.Parse(tokens[1]);
  34.                         string insert = tokens[2];
  35.                         input = input.Insert(index, insert);
  36.                         break;
  37.                     case "Delete":
  38.                         int start = int.Parse(tokens[1]);
  39.                         int end = int.Parse(tokens[2]);
  40.                         input = input.Remove(start, end - start + 1);
  41.                         break;
  42.                 }
  43.  
  44.                 commands = Console.ReadLine();
  45.             }
  46.             Console.WriteLine(input);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement