Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- namespace TextEditor
- {
- class Program
- {
- static void Main()
- {
- int commandCount = int.Parse(Console.ReadLine());
- Stack<string> versions = new Stack<string>();
- StringBuilder text = new StringBuilder();
- versions.Push("");
- for (int i = 0; i < commandCount; i++)
- {
- string[] commandProps = Console.ReadLine().Split();
- string command = commandProps[0];
- switch (command)
- {
- case "1":
- versions.Push(text.ToString());
- string textToAdd = commandProps[1];
- text.Append(textToAdd);
- break;
- case "2":
- versions.Push(text.ToString());
- int removeElementsCount = int.Parse(commandProps[1]);
- text.Remove(text.Length - removeElementsCount, removeElementsCount);
- break;
- case "3":
- int index = int.Parse(commandProps[1]) - 1;
- Console.WriteLine(text[index]);
- break;
- case "4":
- text.Clear();
- text.Append(versions.Pop());
- break;
- default:
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement