Advertisement
Guest User

String Explosion

a guest
Mar 25th, 2019
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.  
  11.             char[] inputAsChars = input.ToCharArray();
  12.             int currentPower = 0;
  13.             string result = string.Empty;
  14.            
  15.             bool isPunch = false;
  16.  
  17.             for (int i = 0; i < inputAsChars.Length; i++)
  18.             {
  19.                 if (inputAsChars[i] == '>')
  20.                 {
  21.                     isPunch = true;
  22.                     continue;
  23.                 }
  24.  
  25.                 if (isPunch)
  26.                 {
  27.                      currentPower += inputAsChars[i] - 48;
  28.                     isPunch = false;
  29.                 }
  30.  
  31.                 if (currentPower > 0)
  32.                 {
  33.                     inputAsChars[i] = '0';
  34.                     currentPower--;
  35.                 }
  36.  
  37.             }
  38.             foreach (var ch in inputAsChars)
  39.             {
  40.                 if (ch != '0')
  41.                 {
  42.                     result += ch;
  43.                 }
  44.             }
  45.             Console.WriteLine(result);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement