angelllo

String Explosion

Jul 17th, 2020
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace String_Explosion
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. StringBuilder input = new StringBuilder();
  11. input.Append(Console.ReadLine());
  12. int strength = 0;
  13.  
  14. for (int i = 0; i < input.Length; i++)
  15. {
  16. if (input[i] == '>')
  17. {
  18. strength += int.Parse(input[i + 1].ToString());
  19.  
  20. if (char.IsLetterOrDigit(input[i + 1]))
  21. {
  22.  
  23. for (int j = i + 1; j < i + 1 + strength; j++)
  24. {
  25. if (strength > input.Length - j - 1)
  26. {
  27. input.Remove(j, input.Length - j);
  28. break;
  29. }
  30.  
  31. if (input[j] != '>')
  32. {
  33. input.Remove(j, 1);
  34. strength -= 1;
  35. j--;
  36. }
  37. }
  38.  
  39. }
  40. }
  41. }
  42. Console.WriteLine(input);
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment