Advertisement
ralichka

SimpleTextEditor

Jan 22nd, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace _09.SimpleTextEditor
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             StringBuilder text = new StringBuilder();
  13.  
  14.             Stack<string> versions = new Stack<string>();
  15.  
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 string[] input = Console.ReadLine().Split();
  19.  
  20.                 string command = input[0];
  21.  
  22.                 if (command != "4")
  23.                 {
  24.                     string action = input[1];
  25.  
  26.                     if (command == "1")
  27.                     {
  28.                         versions.Push(text.ToString());
  29.                         text.Append(action);
  30.                     }
  31.                     else if (command == "2")
  32.                     {
  33.                         versions.Push(text.ToString());
  34.                         text.Remove(text.Length - int.Parse(action), int.Parse(action));
  35.                     }
  36.                     else if (command == "3")
  37.                     {
  38.                         Console.WriteLine(text[int.Parse(action) - 1]);
  39.                     }
  40.  
  41.                 }
  42.                 else
  43.                 {
  44.                     text = new StringBuilder();
  45.                     text.Append(versions.Pop());
  46.                 }
  47.  
  48.  
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement