Advertisement
miroLLL

03Problem-NetherRealms

Mar 2nd, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _03Problem_NetherRealms
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<string> demons = Console.ReadLine().Split(',').Select(x => x.Trim()).OrderBy(x => x).ToList();
  13.  
  14.             string healthPattern = @"[^\d\+\-\\\/\*\.]";
  15.             string damagePattern = @"((-?\d+(\.\d+)?))";
  16.             string mathSymbolPatten = @"[\/*]";
  17.  
  18.             for (int i = 0; i < demons.Count; i++)
  19.             {
  20.                 MatchCollection hpRegex = Regex.Matches(demons[i], healthPattern);
  21.                 MatchCollection dmgRegex = Regex.Matches(demons[i], damagePattern);
  22.                 MatchCollection mathSymbolRegex = Regex.Matches(demons[i], mathSymbolPatten);
  23.  
  24.                 long totalHealth = 0;
  25.                 decimal totalDamage = 0M;
  26.  
  27.                 foreach (Match letter in hpRegex)
  28.                 {
  29.                     totalHealth += letter.Value[0];
  30.                 }
  31.  
  32.                 foreach (Match number in dmgRegex)
  33.                 {
  34.                     totalDamage += decimal.Parse(number.Value);
  35.                 }
  36.  
  37.                 foreach (var mathSymbol in mathSymbolRegex)
  38.                 {
  39.                     if (mathSymbol.ToString().Equals("/"))
  40.                     {
  41.                         totalDamage /= 2;
  42.                     }
  43.                     else if (mathSymbol.ToString().Equals("*"))
  44.                     {
  45.                         totalDamage *= 2;
  46.                     }
  47.                 }
  48.  
  49.                 Console.WriteLine($"{demons[i]} - {totalHealth} health, {totalDamage:0.00} damage");
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement