Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- namespace text
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- string text = Console.ReadLine();
- int explosionPower = 0;
- bool haveMarks = true;
- int startIndex = 0;
- for (int i = 0; i < text.Length; i++)
- {
- if (text[i] == '>')
- {
- explosionPower += int.Parse(text[i + 1].ToString());
- startIndex = i + 1;
- int endIndex = text.IndexOf('>', i + 2);
- if (endIndex == -1)
- {
- haveMarks = false;
- break;
- }
- int lengthBetwenTwoChars = endIndex - startIndex;
- if (explosionPower >= lengthBetwenTwoChars)
- {
- text = text.Remove(startIndex,lengthBetwenTwoChars);
- explosionPower -= lengthBetwenTwoChars;
- }
- else if (explosionPower < lengthBetwenTwoChars)
- {
- text = text.Remove(startIndex, explosionPower);
- explosionPower = 0;
- }
- }
- }
- if (haveMarks == false)
- {
- int lastSubstringLength = text.Length - startIndex;
- if (explosionPower >= lastSubstringLength)
- {
- text = text.Remove(startIndex,lastSubstringLength);
- }
- else if (explosionPower < lastSubstringLength)
- {
- text = text.Remove(startIndex, explosionPower);
- }
- }
- Console.WriteLine(text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement