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 _09.Simple_text_editor
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Stack<char> stack = new Stack<char>();
- Stack<int> undo = new Stack<int>();
- Stack<char> undoAction = new Stack<char>();
- string action = "";
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split(' ').ToArray();
- string command = input[1];
- if (input.Length > 1)
- action = input[2];
- if (command == "1")
- {
- foreach (var item in action)
- {
- stack.Push(item);
- undo.Push(int.Parse(command));
- undoAction.Push(item);
- }
- }
- else if (command == "2")
- for (int j = 0; j < int.Parse(action); j++)
- {
- undoAction.Push(stack.pop);
- undo.Push(int.Parse(command));
- }
- else if (command == "3")
- Console.WriteLine(stack.ElementAt(int.Parse(action)));
- else if (command == "4")
- {
- if (undo.Pop() == 2)
- stack.Push(undoAction.Pop());
- else if (undo.Pop() == 1)
- stack.Pop();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement