Guest User

Nether_Realms

a guest
Nov 27th, 2020
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 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.  
  7. namespace _05._Nether_Realms
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             List<string> input = Console
  15.                       .ReadLine()
  16.                       .Split(", ", StringSplitOptions.RemoveEmptyEntries)
  17.                       .Select(x => x.Trim())
  18.                       .ToList();
  19.             string patternHealth = @"[0-9-+.\/*]+";
  20.             string patternDamage = @"[0-9-+.]+";
  21.             string attack = @"[^\/*]";
  22.             SortedDictionary<string, List<double>> infoDemons = new SortedDictionary<string, List<double>>();
  23.  
  24.             for (int i = 0; i < input.Count; i++)
  25.             {
  26.  
  27.                 int health = 0;
  28.                 string demonLetter = Regex.Replace(input[i], patternHealth, "");
  29.                 if (demonLetter.Length == 0)
  30.                 {
  31.                     continue;
  32.                 }
  33.                 foreach (var character in demonLetter)
  34.                 {
  35.                     health += (char)character;
  36.                 }
  37.                 MatchCollection matchDigits = Regex.Matches(input[i], patternDamage);
  38.                 double damage = 0;
  39.                 foreach (Match num in matchDigits)
  40.                 {
  41.                     damage += double.Parse(num.Value);
  42.                 }
  43.                 string symbols = Regex.Replace(input[i], attack, "");
  44.                 foreach (var symbol in symbols)
  45.                 {
  46.                     if (symbol == '*')
  47.                     {
  48.                         damage *= 2;
  49.                     }
  50.                     else
  51.                     {
  52.                         damage /= 2;
  53.                     }
  54.                 }
  55.                 infoDemons.Add(input[i], new List<double>());
  56.                 infoDemons[input[i]].Add(health);
  57.                 infoDemons[input[i]].Add(damage);
  58.             }
  59.  
  60.             foreach (var demon in infoDemons)
  61.             {
  62.                 Console.WriteLine($"{demon.Key} - {demon.Value[0]} health, {demon.Value[1]:f2} damage");
  63.             }
  64.  
  65.  
  66.  
  67.  
  68.         }
  69.     }
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment