Advertisement
Aborigenius

NetherRealmsRegexASCII

Aug 31st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace NeithterRealms
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string []inputNames = Console.ReadLine().Split(new string[] { ",", " "}, StringSplitOptions.RemoveEmptyEntries);
  15.  
  16.             Regex getDigits = new Regex (@"(?<digits>-*[0-9.0-9]+)");
  17.           SortedDictionary<string, List<double>> result = new SortedDictionary<string, List<double>>();
  18.             foreach (var n in inputNames)
  19.             {
  20.                 string name = n;
  21.  
  22.                 double digitsSumBefore = Regex.Matches(n, @"(?<digits>[-|+]*[0-9.0-9]+)")
  23.                     .Cast<Match>().
  24.                     Select(m => double.Parse(m.Value))
  25.                     .Sum();
  26.  
  27.                 var health = Regex.Matches(n, @"[A-Z]|[a-z]")
  28.                      .Cast<Match>()
  29.                     .Select(c => char.Parse(c.Value))
  30.                     .ToArray();
  31.              byte[] healthASCII = Encoding.ASCII.GetBytes(health);
  32.                 int healthResult = 0;
  33.                 foreach (var b in healthASCII)
  34.                 {
  35.                     healthResult += b;
  36.                 }
  37.            
  38.                 var operators = Regex.Matches(n, @"[\*|\/]")
  39.                     .Cast<Match>()
  40.                     .Select(c => char.Parse(c.Value))
  41.                     .ToArray();
  42.                 double digitSumResult = digitsSumBefore;
  43.  
  44.                 foreach (var op in operators)
  45.                 {
  46.                     if (op == '*')
  47.                     {
  48.                         digitSumResult *= 2;
  49.                     }
  50.                     else
  51.                     {
  52.                         digitSumResult /= 2;
  53.                     }
  54.                 }
  55.  
  56.                 if (!result.ContainsKey(name))
  57.                 {
  58.                     result[name] = new List<double>();
  59.                 }
  60.  
  61.                     result[name].Add(healthResult);
  62.                     result[name].Add(digitSumResult);
  63.                
  64.  
  65.             }
  66.             foreach (KeyValuePair<string, List<double>> demon in result)
  67.             {
  68.                 string demonName = demon.Key;
  69.                 List<double> demonProps = demon.Value;
  70.                 double life = demonProps[0];
  71.                 double damage = demonProps[1];
  72.                 Console.WriteLine($"{demon.Key} - {life} health, {damage:F2} damage");
  73.  
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement