Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- int number = int.Parse(Console.ReadLine());
- string text = string.Empty;
- var stackText = new Stack<string>();
- for (int i = 0; i < number; i++)
- {
- string[] line = Console.ReadLine().Split();
- string command = line[0];
- switch (command)
- {
- case "1":
- string textToAdd = line[1];
- stackText.Push(text);
- text += textToAdd;
- break;
- case "2":
- int count = int.Parse(line[1]);
- if (count > text.Length)
- {
- count = Math.Min(count, text.Length);
- }
- stackText.Push(text);
- text = text.Substring(0, text.Length - count);
- break;
- case "3":
- int index = int.Parse(line[1]);
- Console.WriteLine(text[index - 1]);
- break;
- case "4":
- text = stackText.Pop();
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment