-Annie-

SimpleTextEditor

Jun 4th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. namespace SimpleTextEditor
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.  
  8.     public class SimpleTextEditor
  9.     {
  10.         public static void Main()
  11.         {
  12.             int n = int.Parse(Console.ReadLine());
  13.             Stack<string> myStack = new Stack<string>();
  14.             string str = "";
  15.             myStack.Push(str);
  16.  
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 string[] command =
  20.                     Console.ReadLine()
  21.                     .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  22.                     .ToArray();
  23.  
  24.                 switch (command[0])
  25.                 {
  26.                     case "1":
  27.                         {
  28.                             str += command[1];
  29.                             myStack.Push(str);
  30.                         }
  31.                         break;
  32.  
  33.                     case "2":
  34.                         {
  35.                             int elementsToErase = int.Parse(command[1]);
  36.                             str = str.Substring(0, str.Length - elementsToErase);
  37.                             myStack.Push(str);
  38.                         }
  39.                         break;
  40.  
  41.                     case "3":
  42.                         {
  43.                             int indexToPrint = int.Parse(command[1]);
  44.                             Console.WriteLine(str[indexToPrint - 1]);
  45.                         }
  46.                         break;
  47.  
  48.                     case "4":
  49.                         {
  50.                             myStack.Pop();
  51.                             str = myStack.Peek();
  52.                         }
  53.                         break;
  54.                 }
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment