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 _05.NetherRealms
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] input = Console.ReadLine()
- .Split(',')
- .Select(x => x.Trim())
- .ToArray();
- Regex regexHealth = new Regex(@"[^\d+\-*,\/.]");
- Regex regexDamage = new Regex(@"[+\-]?\d+\.?\d*");
- Regex actionRegex = new Regex(@"[*\/]");
- SortedDictionary<string, double[]> demons = new SortedDictionary<string, double[]>();
- foreach (var demon in input)
- {
- MatchCollection matchHealth = regexHealth.Matches(demon);
- int health = matchHealth
- .Select(x => char.Parse(x.Value))
- .Sum(x => x);
- MatchCollection matchesDamage = regexDamage.Matches(demon);
- double baseDemage = matchesDamage
- .Select(x => double.Parse(x.Value))
- .Sum();
- MatchCollection actionMatches = actionRegex.Matches(demon);
- foreach (Match actionMatch in actionMatches)
- {
- if (actionMatch.Value == "*")
- {
- baseDemage *= 2;
- }
- else
- {
- baseDemage /= 2;
- }
- }
- demons.Add(demon, new Double[] {health, baseDemage});
- }
- foreach (var demon in demons)
- {
- Console.WriteLine($"{demon.Key} - {demon.Value[0]} health, {demon.Value[1]:f2} damage");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement