Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _03_Nether_Realms
- {
- public class NetherRealms
- {
- public static void Main()
- {
- var inputDemons = Console.ReadLine().Split(',').Select(d => d.Trim()).ToArray();
- var damageRegex = new Regex(@"(?<damage>[\+\-]?\d+\.?\d*)");
- var healthRegex = new Regex(@"(?<health>[^\d\+\-\*\.\/])");
- List<Demon> demons = new List<Demon>();
- foreach (var inputDemon in inputDemons)
- {
- decimal damage = damageRegex.Matches(inputDemon)
- .Cast<Match>()
- .Select(d => d.Value)
- .Select(decimal.Parse)
- .Sum();
- var health = healthRegex.Matches(inputDemon)
- .Cast<Match>()
- .Select(d => char.Parse(d.Value))
- .Select(ch => (int)ch)
- .Sum();
- var multiplyCnt = inputDemon.ToCharArray().Count(ch => ch == '*');
- var divideCnt = inputDemon.ToCharArray().Count(ch => ch == '/');
- damage *= (decimal)Math.Pow(2, multiplyCnt);
- damage /= (decimal)Math.Pow(2, divideCnt);
- var demon = new Demon(inputDemon, damage, health);
- demons.Add(demon);
- }
- foreach (var demon in demons.OrderBy(d => d.DemonName))
- {
- Console.WriteLine($"{demon.DemonName} - {demon.Health} health, {demon.Damage:f2} damage");
- }
- }
- }
- public class Demon
- {
- public Demon(string demonName, decimal damage, decimal health)
- {
- DemonName = demonName;
- Damage = damage;
- Health = health;
- }
- public string DemonName { get; set; }
- public decimal Damage { get; set; }
- public decimal Health { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement