Advertisement
krasizorbov

String Explosion

Mar 23rd, 2019
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Collections.Generic;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace String_Explosion
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.  
  15.             StringBuilder sb = new StringBuilder(input);
  16.  
  17.             int counter = 0;
  18.  
  19.             int count = 0;
  20.  
  21.             int j = 0;
  22.  
  23.             int remaining = 0;
  24.  
  25.             int num = 0;
  26.  
  27.             for (int i = 0; i < sb.Length; i++)
  28.             {
  29.                 if (char.IsNumber(sb[i]))
  30.                 {
  31.                     num = (char)sb[i] - '0' + remaining;
  32.  
  33.                     for (j = i; j < i + num; j++)
  34.                     {
  35.                         if (j >= sb.Length)
  36.                         {
  37.                             counter = 1;
  38.                             break;
  39.                         }
  40.                         else if (sb[j] == '>')
  41.                         {
  42.                             counter = 1;
  43.  
  44.                             break;
  45.                         }
  46.                         else
  47.                         {
  48.                             count++;
  49.                             counter = 0;
  50.                         }
  51.                     }
  52.                     if (counter == 0)
  53.                     {
  54.                         sb = sb.Remove(i, num);
  55.                         i = 0;
  56.                     }
  57.                     else if (counter == 1)
  58.                     {
  59.                         if (remaining > sb.ToString().Length - i)
  60.                         {
  61.                             remaining = sb.ToString().Length - i;
  62.                             sb = sb.Remove(i, remaining);
  63.                         }
  64.                         else
  65.                         {
  66.                             remaining = num - count;
  67.                             sb = sb.Remove(i, j - i);
  68.                         }
  69.                         i = 0;
  70.                     }
  71.                 }
  72.                 count = 0;
  73.                 num = 0;
  74.             }
  75.             Console.WriteLine(sb);
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement