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 ConsoleApp231
- {
- class Program
- {
- static void Main(string[] args)
- {
- var text = Console.ReadLine();
- while (true)
- {
- var command = Console.ReadLine().Split();
- if (command[0] == "end")
- {
- break;
- }
- if (command[0] == "Left")
- {
- var count = int.Parse(command[1]);
- for (int i = 0; i < count; i++)
- {
- var firstSymbol = text[0];
- text = text.Remove(0, 1);
- text += firstSymbol;
- }
- }
- if (command[0] == "Right")
- {
- var count = int.Parse(command[1]);
- for (int i = 0; i < count; i++)
- {
- var lastSymbol = text[text.Length-1];
- text = text.Remove(text.Length - 1, 1);
- var finalresult = (lastSymbol + text);
- text = finalresult;
- }
- }
- if (command[0] == "Insert")
- {
- var index = int.Parse(command[1]);
- text = text.Insert(index, command[2]);
- }
- if (command[0] == "Delete")
- {
- var startIndex = int.Parse(command[1]);
- var endIndex = int.Parse(command[2]);
- var len = text.Length - startIndex;
- if(startIndex>=0 && endIndex <= len)
- {
- text = text.Remove(startIndex, endIndex + 1);
- }
- else
- {
- text = text.Remove(startIndex, len);
- }
- }
- }
- Console.WriteLine(text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement