static void Main(string[] args) { string[] demons = Console.ReadLine() .Split(new char[] { ',', ' ', '\t' }, StringSplitOptions .RemoveEmptyEntries); Regex patternHealth = new Regex(@"[^0-9\+\-\*\/\.]+"); Regex patternDamage = new Regex(@"-?\d+(?:\.\d+)*"); Regex pattern = new Regex(@"[*\/]"); List <Demon> dataDemons = new List <Demon>(); foreach (var demon in demons) { string name = demon; MatchCollection matchesHealth = patternHealth.Matches(demon); long sumHealth = TakeHealth(matchesHealth); MatchCollection matchesDamage = patternDamage.Matches(demon); decimal sumDamage = TakeDamage(matchesDamage); MatchCollection matchSymbols = pattern.Matches(demon); string symbols = TakeSymbols(matchSymbols); sumDamage = TotalDamage(symbols, sumDamage); Demon currDemon = new Demon() { Name = name, Health = sumHealth, Damage = sumDamage }; dataDemons.Add(currDemon); } PrintDemons(dataDemons); }
static void Main(string[] args) { string[] demonsNames = Console.ReadLine() .Split(new char[] { ' ', ',', '\t' }, StringSplitOptions .RemoveEmptyEntries); List <Demon> demons = new List <Demon>(); for (int i = 0; i < demonsNames.Length; i++) { Regex healthPattern = new Regex(@"(?<healt>[^0-9\+\-\*\/\.]+)"); Regex damagePattern = new Regex(@"(?<num>-?\d+\.?\d*)"); //Regex damagePattern = new Regex(@"(?<num>[+|\-]?\d+(\.)?(\d+)?)"); Regex symbolsPattern = new Regex(@"(?<symbols>[*\/]+)"); MatchCollection healthMatch = healthPattern.Matches(demonsNames[i]); MatchCollection damageMatch = damagePattern.Matches(demonsNames[i]); MatchCollection symbolsMatch = symbolsPattern.Matches(demonsNames[i]); int sumHealth = TakeHealth(healthMatch); double damage = TakeDamage(damageMatch, symbolsMatch); Demon currentDemon = new Demon ( demonsNames[i], sumHealth, damage ); demons.Add(currentDemon); } PrintDemons(demons); }