Advertisement
riff-raff

03. Nether Realms

Aug 23rd, 2018
196
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 _03.Nether_Realms
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             string healthPattern = @"[^0-9+\-\*\/.]";
  14.             string damagePattern = @"([\-\+]?[\d]+[\.]?[\d]+|[\d])";
  15.  
  16.             //all numbers = baseDamage
  17.             string[] demonsNames = Console.ReadLine().Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
  18.  
  19.             double health = 0;
  20.             double damage = 0;
  21.  
  22.             foreach (var demon in demonsNames.OrderBy(x => x))
  23.             {
  24.                 //HEALTH
  25.                 MatchCollection matches = Regex.Matches(demon, healthPattern);
  26.  
  27.                 foreach (Match match in matches)
  28.                 {
  29.                     foreach (var x in match.ToString())
  30.                     {
  31.                         health += (int)x;
  32.                     }
  33.                 }
  34.  
  35.                 // DAMAGE
  36.                 MatchCollection damageMatches = Regex.Matches(demon, damagePattern);
  37.  
  38.                 foreach (var currentDamage in damageMatches)
  39.                 {
  40.                     damage += double.Parse(currentDamage.ToString());
  41.                 }
  42.  
  43.                 foreach (char x in demon.Where(x => x == '*' || x == '/'))
  44.                 {
  45.                     if (x == '*')
  46.                     {
  47.                         damage = damage * 2;
  48.                     }
  49.  
  50.                     if (x == '/')
  51.                     {
  52.                         damage = damage / 2;
  53.                     }
  54.                 }
  55.  
  56.                 Console.WriteLine($"{demon} - {health} health, {damage:F2} damage");
  57.  
  58.                 health = 0;
  59.                 damage = 0;
  60.             }
  61.  
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement