Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace _09.SimpleTextEditor
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- StringBuilder text = new StringBuilder();
- Stack<string> versions = new Stack<string>();
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split();
- string command = input[0];
- if (command != "4")
- {
- string action = input[1];
- if (command == "1")
- {
- versions.Push(text.ToString());
- text.Append(action);
- }
- else if (command == "2")
- {
- versions.Push(text.ToString());
- text.Remove(text.Length - int.Parse(action), int.Parse(action));
- }
- else if (command == "3")
- {
- Console.WriteLine(text[int.Parse(action) - 1]);
- }
- }
- else
- {
- text = new StringBuilder();
- text.Append(versions.Pop());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement