Advertisement
Guest User

Simple Text Editor

a guest
May 27th, 2017
1,698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _10.SimpleTextEditor
  8. {
  9. public class SimpleTextEditor
  10. {
  11. public static void Main()
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. string text = "";
  16.  
  17. var stack = new Stack<string>();
  18.  
  19. for (int i = 0; i < n; i++)
  20. {
  21. string[] commandArgs = Console.ReadLine().Split();
  22.  
  23. if (commandArgs[0] == "1")
  24. {
  25. text = commandArgs[1];
  26. stack.Push(text);
  27. }
  28.  
  29. else if (commandArgs[0] == "2")
  30. {
  31. int eraseNum = int.Parse(commandArgs[1]);
  32.  
  33. if (text.Length == eraseNum)
  34. {
  35. text = "";
  36. }
  37.  
  38. else
  39. {
  40. text = text.Take(text.Length - eraseNum).ToString();
  41. }
  42.  
  43. stack.Push(text);
  44. }
  45.  
  46. else if (commandArgs[0] == "3")
  47. {
  48. int index = int.Parse(commandArgs[1]);
  49. Console.WriteLine(text[index - 1]);
  50. }
  51. else
  52. {
  53. stack.Pop();
  54. text = stack.Peek();
  55. }
  56.  
  57. }
  58.  
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement