Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1.  using System;
  2.  using System.Collections.Generic;
  3. namespace _10_Simple_Text_Editor
  4.  
  5. {
  6.    
  7.  
  8.     public class SimpleTextEditor
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             int n = int.Parse(Console.ReadLine());
  13.  
  14.             Stack<string> previousCommands = new Stack<string>();
  15.  
  16.             string text = string.Empty;
  17.  
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 string[] commands = Console.ReadLine()
  21.                                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  22.                 switch (commands[0])
  23.                 {
  24.                     case "1":
  25.                         previousCommands.Push(text);
  26.                         text += commands[1];
  27.                         break;
  28.  
  29.                     case "2":
  30.                         previousCommands.Push(text);
  31.                         text = text.Substring(0, text.Length - int.Parse(commands[1]));
  32.                         break;
  33.  
  34.                     case "3":
  35.                         Console.WriteLine(text[int.Parse(commands[1]) - 1]);
  36.                         break;
  37.  
  38.                     case "4":
  39.                         text = previousCommands.Pop();
  40.                         break;
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement