Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. namespace _Simple_Text_Editor
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int n = int.Parse(Console.ReadLine());
  10.  
  11. string manipulete = string.Empty;
  12.  
  13. Stack<string> operations = new Stack<string>();
  14.  
  15. for (int i = 0; i < n; i++)
  16. {
  17. string[] command = Console.ReadLine()
  18. .Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  19. if (command[0] == "1")
  20. {
  21. operations.Push(manipulete);
  22. manipulete += command[1];
  23.  
  24. }
  25. else if (command[0] == "2" &&
  26. int.Parse(command[1]) <= manipulete.Length)
  27. {
  28. operations.Push(manipulete);
  29. manipulete = manipulete.Remove(manipulete.Length - int.Parse(command[1]), int.Parse(command[1]));
  30.  
  31. }
  32. else if (command[0] == "3" &&
  33. int.Parse(command[1]) > 0 &&
  34. int.Parse(command[1]) - 1 < manipulete.Length)
  35. {
  36. Console.WriteLine(manipulete[int.Parse(command[1]) - 1]);
  37. }
  38. else if (command[0] == "4")
  39. {
  40. manipulete = operations.Pop();
  41. }
  42. }
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement