Guest User

Untitled

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