TheBulgarianWolf

String Explosion

Mar 21st, 2021
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace StringExplosion
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter your string here: ");
  11.             string[] input = Console.ReadLine().Split(">");
  12.             List<string> endList = new List<string>();
  13.             foreach(string str in input)
  14.             {
  15.                 endList.Add(str);
  16.             }
  17.             int powerStack = 0;
  18.             for(int i = 1; i < input.Length; i++)
  19.             {
  20.  
  21.                 int power = int.Parse((input[i][0]).ToString()) + powerStack;
  22.                 if (power > input[1].Length)
  23.                 {
  24.                     powerStack = power - input[i].Length;
  25.                     endList.RemoveAt(i);
  26.                     endList.Insert(i, "");
  27.                 }
  28.                 else
  29.                 {
  30.                     int len = input[i].Length-power;
  31.                     string newString =input[i].Substring(power, len);
  32.                     endList.RemoveAt(i);
  33.                     endList.Insert(i, newString);
  34.                 }
  35.             }
  36.  
  37.             for(int k = 0; k < endList.Count - 1; k++)
  38.             {
  39.                 Console.Write(endList[k] + ">");
  40.             }
  41.             Console.Write(endList[endList.Count - 1]);
  42.         }
  43.     }
  44. }
  45.  
Add Comment
Please, Sign In to add comment