07. String Explosion
Здравейте имам проблем с задача 07. String Explosion от Programming Fundamentals C#/Text Processing/Exercise. Дава ми 25/100 и понеже не намерих решение подобно на моето а аз искам да разбера как да я реша по моя начин моля за помощ. Благодаря предварително
Условие:
Explosions are marked with '>'. Immediately after the mark, there will be an integer, which signifies the strength of the explosion.
You should remove x characters (where x is the strength of the explosion), starting after the punched character ('>').
If you find another explosion mark ('>') while you're deleting characters, you should add the strength to your previous explosion.
When all characters are processed, print the string without the deleted characters.
You should not delete the explosion character – '>', but you should delete the integers, which represent the strength.
Моето решение:
using System;
using System.Linq;
using System.Collections.Generic;
namespace zad._7
{
class Program
{
static void Main(string[] args)
{
var input = Console.ReadLine().ToList();
int leftover = 0;
for (int i = 0; i < input.Count; i++)
{
int strength = 0;
if (input[i]=='>')
{
strength = int.Parse(input[i + 1].ToString()) + leftover;
leftover = 0;
}
if (strength==1)
{
input.RemoveAt(i + 1);
}
else if(strength>1)
{
for (int j = 0; j < strength; j++)
{
if (input[i + 1] != '>')
{
if (strength<=input.Count)
{
input.RemoveAt(i + 1);
}
}
}
leftover = strength - 1;
}
}
Console.WriteLine(string.Join("", input));
}
}
}