Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SimpleTextEditor
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- public class SimpleTextEditor
- {
- public static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- Stack<string> myStack = new Stack<string>();
- string str = "";
- myStack.Push(str);
- for (int i = 0; i < n; i++)
- {
- string[] command =
- Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- switch (command[0])
- {
- case "1":
- {
- str += command[1];
- myStack.Push(str);
- }
- break;
- case "2":
- {
- int elementsToErase = int.Parse(command[1]);
- str = str.Substring(0, str.Length - elementsToErase);
- myStack.Push(str);
- }
- break;
- case "3":
- {
- int indexToPrint = int.Parse(command[1]);
- Console.WriteLine(str[indexToPrint - 1]);
- }
- break;
- case "4":
- {
- myStack.Pop();
- str = myStack.Peek();
- }
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment