GerganaTsirkova

Nether Realms

Mar 3rd, 2018
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _3.NetherRealms
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string[] input = Console.ReadLine()
  13.                 .Split(new char[] {',',' '}, StringSplitOptions.RemoveEmptyEntries)
  14.                 .ToArray();
  15.             SortedDictionary<string, Dictionary<decimal, decimal>> dataDemons = new SortedDictionary<string, Dictionary<decimal, decimal>>();
  16.             foreach (var demon in input)
  17.             {
  18.                 decimal health = 0;
  19.                 decimal damage = 0;
  20.                 //match only digits like -5.2, 5 +2.6 .....
  21.                 string patternDigits = @"[+-]?[\d+\.]*[\d]+";
  22.                 var regDigits = new Regex(patternDigits);
  23.                 MatchCollection matchDigits = regDigits.Matches(demon);
  24.                 if(matchDigits.Count>0)
  25.                 {
  26.                     foreach (Match digit in matchDigits)
  27.                     {
  28.                         string temp = digit.ToString();
  29.                         decimal num = decimal.Parse(temp);
  30.                         damage += num;
  31.                     }
  32.                 }
  33.                 string patternChars = @"[A-Za-z]*[^\d\.\+\-\*\/\s]+";
  34.                 var regChars = new Regex(patternChars);
  35.                 MatchCollection matchChar = regChars.Matches(demon);
  36.                 if(matchChar.Count>0)
  37.                 {
  38.                     foreach (Match letters in matchChar)
  39.                     {
  40.                         string temp = letters.ToString();
  41.                         foreach (var ch in temp)
  42.                         {
  43.                             health += (int)ch;
  44.                         }
  45.                     }
  46.                 }
  47.                
  48.                 string patternSign = @"[*\|/]";
  49.                 var regsigns = new Regex(patternSign);
  50.                 MatchCollection matchSigns = regsigns.Matches(demon);
  51.                 if(matchSigns.Count>0)
  52.                 {
  53.                     foreach (Match sign in matchSigns)
  54.                     {
  55.                         string c = sign.ToString();
  56.                         if (c == "/")
  57.                         {
  58.                             damage *= 2;
  59.                         }
  60.                         else if (c == "*")
  61.                         {
  62.                             damage *= 2;
  63.                         }
  64.                     }
  65.                 }
  66.                 var inner = new Dictionary<decimal, decimal>();
  67.                 inner.Add(health, damage);
  68.                 dataDemons.Add(demon, inner);
  69.  
  70.             }
  71.             foreach (var item in dataDemons)
  72.             {
  73.                 Console.Write("{0} - ", item.Key);
  74.                 foreach (var i in item.Value)
  75.                 {
  76.                     Console.WriteLine("{0} health, {1:f2} damage", i.Key, i.Value);
  77.                 }
  78.             }
  79.         }
  80.  
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment