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