Advertisement
ivo_petkov01

07. String Explosion

Mar 14th, 2023
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace _07._String_Explosion_2
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string inputLine = Console.ReadLine();
  11.  
  12.             int bombPower = 0;
  13.  
  14.             for (int i = 0; i < inputLine.Length; i++)
  15.             {
  16.                 char currentChar = inputLine[i];
  17.  
  18.                 if (currentChar == '>')
  19.                 {
  20.                     bombPower += int.Parse(inputLine[i + 1].ToString());
  21.                 }
  22.                 else if (bombPower > 0 && currentChar != '>')
  23.                 {
  24.                     inputLine = inputLine.Remove(i, 1);
  25.                     bombPower--;
  26.                     i--;
  27.                 }
  28.             }
  29.  
  30.             Console.WriteLine(inputLine);
  31.         }
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement