Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Problem09SimpleTextEditor
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfOperations = int.Parse(Console.ReadLine());
- string result = string.Empty;
- Stack<string> stack = new Stack<string>();
- for (int i = 1; i <= numberOfOperations; i++)
- {
- string[] currentCommand = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries);
- if (currentCommand[0] == "1")
- {
- stack.Push(result);
- string stringToAppend = currentCommand[1];
- result += stringToAppend;
- }
- else if (currentCommand[0] == "2")
- {
- stack.Push(result);
- int count = int.Parse(currentCommand[1]);
- if (result.Length >= count)
- {
- string substringToRemove = string.Empty;
- for (int j = result.Length - count; j < result.Length; j++)
- {
- substringToRemove += result[j];
- }
- result = result.Replace(substringToRemove, "");
- }
- }
- else if (currentCommand[0] == "3")
- {
- int index = int.Parse(currentCommand[1]);
- Console.WriteLine(result[index - 1]);
- }
- else if (currentCommand[0] == "4")
- {
- if (stack.Count > 0)
- {
- result = stack.Pop();
- }
- else
- {
- result = string.Empty;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement