Advertisement
yanass

String Explosion

Jul 29th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace String_Explosion
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             string[] input = Console.ReadLine()
  12.                 .Split('>')
  13.                 .ToArray();
  14.  
  15.             int finalCountRemove = 0;
  16.  
  17.             for (int i = 0; i < input.Length; i++)
  18.             {
  19.                 if (input[i][0] >= '0' && input[i][0] <= '9')
  20.                 {
  21.                     int killCount = (int)input[i][0] - 48;
  22.                     finalCountRemove += killCount;
  23.                     if (finalCountRemove >= input[i].Length)
  24.                     {
  25.                         finalCountRemove -= input[i].Length;
  26.                         input[i] = input[i].Remove(0, input[i].Length);
  27.                     }
  28.  
  29.                     else
  30.                     {
  31.                         input[i] = input[i].Remove(0, finalCountRemove);
  32.                         finalCountRemove = 0;
  33.                     }
  34.                 }
  35.             }
  36.             Console.WriteLine(string.Join('>', input));
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement