Advertisement
Guest User

03. Nether Realms

a guest
Jul 6th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace _03.Nether_Realms
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var input = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).OrderBy(n => n).ToList();
  15.  
  16.             Regex digetRegex = new Regex(@"([-+]?(\d*\.)?\d)");
  17.             Regex letersRegex = new Regex(@"[^\d+\-*/.]");
  18.            
  19.  
  20.             var damage = 0.0;
  21.             var health = 0.0;
  22.             var name = "";
  23.                      
  24.            
  25.                 for (int i = 0; i < input.Count; i++)
  26.                 {
  27.                     var matchDemonsDamage = digetRegex.Matches(input[i]).Cast<Match>().Select(d => double.Parse(d.Value)).Sum();
  28.                     var matchDemonsHealth = letersRegex.Matches(input[i]).Cast<Match>().Select(h => (int)char.Parse(h.Value)).Sum();
  29.  
  30.                     var multiplyCount = input[i].Count(m => m == '*');
  31.                     var delenie = input[i].Count(m => m == '/');
  32.  
  33.                     if (multiplyCount > 0)
  34.                     {
  35.                         matchDemonsDamage *= Math.Pow(2, multiplyCount);
  36.                     }
  37.                     if (delenie > 0)
  38.                     {
  39.                         matchDemonsDamage /= Math.Pow(2, delenie);
  40.                     }
  41.                     damage = matchDemonsDamage;
  42.                     health = matchDemonsHealth;
  43.                     name = input[i];
  44.  
  45.                     Console.WriteLine($"{name} - {health} health, {damage:0.00} damage");
  46.  
  47.                 }
  48.  
  49.  
  50.                
  51.                
  52.            
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement