Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Simple_Text_Editor
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numOpper = int.Parse(Console.ReadLine());
- StringBuilder currentText = new StringBuilder(string.Empty);
- StringBuilder printText = new StringBuilder();
- Stack<StringBuilder> stack = new Stack<StringBuilder>();
- for (int i = 0; i < numOpper; i++)
- {
- string[] input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
- int command = int.Parse(input[0]);
- switch (command)
- {
- case 1:
- stack.Push(currentText);
- currentText = new StringBuilder(currentText.ToString());
- currentText.Append(input[1]);
- break;
- case 2:
- stack.Push(currentText);
- int count = int.Parse(input[1]);
- if (count >= currentText.Length)
- {
- currentText = new StringBuilder(string.Empty);
- }
- else
- {
- string newText = currentText.ToString().Substring(0, currentText.Length - count);
- currentText = new StringBuilder(newText);
- }
- break;
- case 3:
- int index = int.Parse(input[1]);
- if (((index - 1) < currentText.Length) && ((index - 1) >= 0))
- {
- printText.AppendLine(currentText[index - 1].ToString());
- }
- break;
- case 4:
- currentText = new StringBuilder(stack.Pop().ToString());
- break;
- default:
- break;
- }
- }
- Console.WriteLine(printText.ToString());
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement