Advertisement
GabrielDas

Untitled

Mar 21st, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P07ExerciseStringExplosion
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string input = Console.ReadLine();
  10. int strength = 0;
  11.  
  12. for (int i = 0; i < input.Length - 1; i++)
  13. {
  14.  
  15. if (input[i] == '>')
  16. {
  17. strength += int.Parse(input[i + 1].ToString());
  18. string key = String.Empty;
  19.  
  20.  
  21. if (strength + i >= input.Length)
  22. {
  23.  
  24. key = input.Substring(i+1, input.Length-i-1); // >3>3asr
  25. }
  26. else
  27. {
  28. key = input.Substring(i + 1, strength);
  29. }
  30.  
  31. if (!key.Contains('>'))
  32. {
  33. input = input.Remove(i + 1, key.Length);
  34. strength = 0;
  35.  
  36. }
  37. else
  38. {
  39. string newKey = key.Substring(0, key.IndexOf('>'));
  40. input = input.Remove(i + 1, newKey.Length);
  41.  
  42. strength = strength - newKey.Length;
  43.  
  44. }
  45. }
  46.  
  47. }
  48.  
  49. Console.WriteLine(input);
  50.  
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement