Advertisement
GabrielDas

Untitled

May 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace P09SimpleTextEditor
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. StringBuilder sb = new StringBuilder();
  12. var unchangedText = new Stack<string>();
  13.  
  14. int numberOfCommands = int.Parse(Console.ReadLine());
  15.  
  16. for (int i = 0; i < numberOfCommands; i++)
  17. {
  18. string[] command = Console.ReadLine().Split();
  19.  
  20. if (command[0] == "1")
  21. {
  22. unchangedText.Push(sb.ToString());
  23.  
  24. string textToAdd = command[1];
  25. sb.Append(textToAdd);
  26. // Console.WriteLine(sb);
  27. }
  28. else if (command[0] == "2")
  29. {
  30. unchangedText.Push(sb.ToString());
  31.  
  32. int symbolsToDelete = int.Parse(command[1]);
  33.  
  34. if (symbolsToDelete >= sb.Length)
  35. {
  36. symbolsToDelete = sb.Length;
  37. sb.Clear();
  38. }
  39. else
  40. {
  41. sb.Remove(sb.Length - symbolsToDelete, symbolsToDelete);
  42.  
  43. }
  44. //Console.WriteLine(sb);
  45. }
  46. else if (command[0] == "3")
  47. {
  48. int indexToGet = int.Parse(command[1]);
  49.  
  50. if (sb.Length == 0)
  51. {
  52. break;
  53. }
  54.  
  55. if (indexToGet >= sb.Length)
  56. {
  57. indexToGet = sb.Length;
  58. }
  59.  
  60. string tempText = sb.ToString();
  61. Console.WriteLine($"{tempText[indexToGet-1]}");
  62.  
  63. }
  64. else if(command[0] == "4")
  65. {
  66. string tempText = sb.ToString();
  67. tempText = unchangedText.Pop();
  68. sb.Clear();
  69. sb.Append(tempText);
  70.  
  71. }
  72.  
  73. }
  74.  
  75.  
  76.  
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement