MiroslavKisov

SimpleTextEditor

Jan 25th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace SimpleTextEditor
  7. {
  8.     public class StartUp
  9.     {
  10.         public static void Main()
  11.         {
  12.             var numberOfCommands = int.Parse(Console.ReadLine());
  13.             var stack = new Stack<string>();
  14.             var text = new StringBuilder();
  15.             stack.Push("");
  16.             for (int i = 0; i < numberOfCommands; i++)
  17.             {
  18.                 var command = Console.ReadLine()
  19.                     .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  20.                     .ToArray();
  21.  
  22.                 if (command[0].StartsWith("1"))
  23.                 {
  24.                     stack.Push(text.ToString());
  25.                     text.Append(command[1]);
  26.                 }
  27.                 else if (command[0].StartsWith("2"))
  28.                 {
  29.                     stack.Push(text.ToString());
  30.                     var count = int.Parse(command[1]);
  31.                     text.Remove(text.Length - count, count);
  32.                 }
  33.                 else if (command[0].StartsWith("3"))
  34.                 {
  35.                     var index = int.Parse(command[1]);
  36.                     Console.WriteLine(text[index - 1]);
  37.                 }
  38.                 else if (command[0].StartsWith("4"))
  39.                 {
  40.                     text.Clear();
  41.                     text.Append(stack.Pop());
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment