joro_thexfiles

_5._Nether_Realms

Aug 1st, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.92 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace _5._Nether_Realms
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             //string[] names = Console.ReadLine()
  13.             //    .Split(new char[] { ' ', ',' , '\t'}, StringSplitOptions.RemoveEmptyEntries);
  14.  
  15.             var dict = new Dictionary<string, Dictionary<string, double>>();
  16.  
  17.             string[] names = Regex
  18.                 .Split(Console.ReadLine(), @"\s*,\s*")
  19.                 .OrderBy(x=>x)
  20.                 .ToArray();
  21.  
  22.  
  23.             int countOfNames = names.Length;
  24.  
  25.             for (int i = 0; i < countOfNames; i++)
  26.             {
  27.                 string currentName = names[i];
  28.                 double health = 0;
  29.                 double damage = 0;
  30.  
  31.                 Regex healthPattern = new Regex(@"[^0-9+\-*\/.]");
  32.                 Regex damagePattern = new Regex(@"(\+|-)?\d+\.?\d*");
  33.                 Regex mdSymbolsPattern = new Regex(@"[*\/]");
  34.  
  35.                 MatchCollection matchesHealth = healthPattern.Matches(currentName);
  36.  
  37.                 foreach (Match symbol in matchesHealth)
  38.                 {
  39.                     health += char.Parse(symbol.Value);
  40.                 }
  41.  
  42.                 MatchCollection matchesDamage = damagePattern.Matches(currentName);
  43.  
  44.                 foreach (Match item in matchesDamage)
  45.                 {
  46.                     damage += double.Parse(item.Value);
  47.                 }
  48.  
  49.                 MatchCollection mdSymbols = mdSymbolsPattern.Matches(currentName);
  50.  
  51.                 foreach (Match symbol in mdSymbols)
  52.                 {
  53.                     if (symbol.Value == "*")
  54.                     {
  55.                         damage *= 2;
  56.                     }
  57.                     else
  58.                     {
  59.                         damage /= 2;
  60.                     }
  61.                 }
  62.  
  63.                 if (!dict.ContainsKey(currentName))
  64.                 {
  65.                     dict[currentName] = new Dictionary<string, double>();
  66.                     dict[currentName]["health"] = health;
  67.                     dict[currentName]["damage"] = damage;
  68.                 }
  69.  
  70.             Console.WriteLine($"{currentName} - {health} health, {damage:F2} damage");
  71.  
  72.             }
  73.  
  74.  
  75.  
  76.             //foreach (var kvp in dict
  77.             //    .OrderBy(x => x.Key))
  78.             //{
  79.             //    int counter = 1;
  80.  
  81.             //    foreach (var item in kvp.Value)
  82.             //    {
  83.             //        if (counter == 1)
  84.             //        {
  85.             //            Console.Write($"{kvp.Key} - {item.Value} health, ");
  86.             //        }
  87.             //        else if (counter == 2)
  88.             //        {
  89.             //            Console.WriteLine($"{item.Value:F2} damage");
  90.             //        }
  91.             //        counter++;
  92.             //    }
  93.             //}
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment