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 _10.SimpleTextEditor
- {
- public class SimpleTextEditor
- {
- public static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- string text = "";
- var stack = new Stack<string>();
- for (int i = 0; i < n; i++)
- {
- string[] commandArgs = Console.ReadLine().Split();
- if (commandArgs[0] == "1")
- {
- text = commandArgs[1];
- stack.Push(text);
- }
- else if (commandArgs[0] == "2")
- {
- int eraseNum = int.Parse(commandArgs[1]);
- if (text.Length == eraseNum)
- {
- text = "";
- }
- else
- {
- text = text.Take(text.Length - eraseNum).ToString();
- }
- stack.Push(text);
- }
- else if (commandArgs[0] == "3")
- {
- int index = int.Parse(commandArgs[1]);
- Console.WriteLine(text[index - 1]);
- }
- else
- {
- stack.Pop();
- text = stack.Peek();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement