Advertisement
DeeAG

05.NetherRealms

Mar 31st, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _05.NetherRealms
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string[] input = Console.ReadLine()
  13.                 .Split(',')
  14.             .Select(x => x.Trim())
  15.             .ToArray();
  16.            
  17.             Regex regexHealth = new Regex(@"[^\d+\-*,\/.]");
  18.             Regex regexDamage = new Regex(@"[+\-]?\d+\.?\d*");
  19.             Regex actionRegex = new Regex(@"[*\/]");
  20.  
  21.             SortedDictionary<string, double[]> demons = new SortedDictionary<string, double[]>();
  22.  
  23.             foreach (var demon in input)
  24.             {
  25.                 MatchCollection matchHealth = regexHealth.Matches(demon);
  26.                 int health = matchHealth
  27.                     .Select(x => char.Parse(x.Value))
  28.                     .Sum(x => x);
  29.  
  30.                 MatchCollection matchesDamage = regexDamage.Matches(demon);
  31.                 double baseDemage = matchesDamage
  32.                     .Select(x => double.Parse(x.Value))
  33.                     .Sum();
  34.  
  35.                 MatchCollection actionMatches = actionRegex.Matches(demon);
  36.  
  37.                 foreach (Match actionMatch in actionMatches)
  38.                 {
  39.                     if (actionMatch.Value == "*")
  40.                     {
  41.                         baseDemage *= 2;
  42.                     }
  43.                     else
  44.                     {
  45.                         baseDemage /= 2;
  46.                     }
  47.                 }
  48.  
  49.                 demons.Add(demon, new Double[] {health, baseDemage});
  50.             }
  51.  
  52.             foreach (var demon in demons)
  53.             {
  54.                Console.WriteLine($"{demon.Key} - {demon.Value[0]} health, {demon.Value[1]:f2} damage");
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement