Advertisement
Krum_50

Strinf Explozien

Jan 1st, 2024
783
0
220 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | Software | 0 0
  1. using System;
  2.  
  3. namespace String_Explosion
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.             int strength = 0;
  11.             int i = 0;
  12.             int lengthOfString = input.Length;
  13.             while (i < lengthOfString)
  14.             {
  15.                 if (input[i] == '>')
  16.                 {
  17.                     strength = int.Parse(input[i + 1].ToString());
  18.                
  19.                     if (strength == 1)
  20.                     {
  21.                         input.Remove(i + 1);
  22.                         i++;
  23.                     }
  24.                     else
  25.                     {
  26.                         for (int j = 0; j < i + strength; j++)
  27.                         {
  28.                             if (input[j] != '>')
  29.                             {
  30.                                 input.Remove(j);
  31.                             }
  32.                             else
  33.                             {
  34.                                 i += j;
  35.                             }
  36.                         }
  37.                     }
  38.                 }
  39.                 else
  40.                 {
  41.                     i++;
  42.                 }
  43.             }
  44.  
  45.             Console.WriteLine(input);                              
  46.                
  47.         }
  48.     }
  49. }
  50.  
Tags: C#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement