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;
- namespace _9._Simple_Text_Editor_REAL_EXE
- {
- class Program
- {
- static void Main(string[] args)
- {
- int countOfOperations = int.Parse(Console.ReadLine());
- var stack = new Stack<string>();
- StringBuilder stringBuilder = new StringBuilder();
- string finalText = string.Empty;
- for (int i = 0; i < countOfOperations; i++)
- {
- var command = Console.ReadLine();
- var commandInList = command.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray();
- if (commandInList[0] == "1")
- {
- stack.Push(command);
- stringBuilder.Append(commandInList[1]);
- finalText += stringBuilder.ToString();
- stringBuilder = new StringBuilder();
- }
- else if (commandInList[0] == "2")
- {
- int count = int.Parse(commandInList[1]);
- int startIndex = (finalText.Length) - count;
- if (startIndex >= 0)
- {
- string erasedText = finalText.Substring(startIndex, count);
- finalText = finalText.Remove(startIndex, count);
- stack.Push(erasedText);
- }
- }
- else if (commandInList[0] == "3")
- {
- int position = int.Parse(commandInList[1]) - 1;
- if (position < finalText.Length && position >= 0)
- {
- Console.WriteLine(finalText[position]);
- }
- }
- else if (commandInList[0] == "4")
- {
- if (stack.Any())
- {
- string com = stack.Pop();
- if (com.StartsWith('1'))
- {
- com = com.Remove(0, 2);
- int index = finalText.IndexOf(com);
- finalText = finalText.Remove(index, com.Length);
- }
- else
- {
- finalText += com;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement