Advertisement
mdamyanova

SimpleTextEditor

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