Advertisement
dragonbs

Nether Realms

Mar 22nd, 2023 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5.  
  6.  
  7. public class Demon
  8. {
  9.     public string Name { get; set; }
  10.  
  11.     public int Health { get; set; }
  12.  
  13.     public double Damage { get; set; }
  14.  
  15.     public Demon(string name)
  16.     {
  17.         this.Name = name;
  18.     }
  19.  
  20.     public override string ToString()
  21.     => $"{this.Name} - {this.Health} health, {this.Damage:f2} damage";
  22. }
  23.  
  24.  
  25. internal class Program
  26. {
  27.     static void Main()
  28.     {
  29.         List<Demon> demons = GetDemonNames();
  30.         for (int i = 0; i < demons.Count; i++)
  31.         {
  32.             demons[i].Health = GetDemonsHealth(demons[i].Name);
  33.             demons[i].Damage = GetDemonsDamage(demons[i].Name);
  34.         }
  35.         Console.WriteLine(String.Join(Environment.NewLine, demons.OrderBy(x => x.Name)));
  36.     }
  37.  
  38.     private static List<Demon> GetDemonNames()
  39.     {
  40.         string[] names = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  41.         List<Demon> demons = new List<Demon>();
  42.         foreach (string name in names)
  43.             demons.Add(new Demon(name));
  44.         return demons;
  45.     }
  46.  
  47.     private static int GetDemonsHealth(string name)
  48.     {
  49.         MatchCollection matchHealth = Regex.Matches(name, @"[^\d+\-\/*\.]");
  50.         string healthText = String.Join("", matchHealth);
  51.         return healthText.Sum(x => (int)x);
  52.     }
  53.  
  54.     private static double GetDemonsDamage(string name)
  55.     {
  56.         MatchCollection matchDamageSum = Regex.Matches(name, @"[-]?\d*[.]?[\d]+");
  57.         MatchCollection matchDamageMultiplier = Regex.Matches(name, @"[*]");
  58.         MatchCollection matchDamageDivision = Regex.Matches(name, @"[\/]");
  59.  
  60.         double damage = matchDamageSum.Select(x => double.Parse(x.Value)).Sum();
  61.  
  62.         damage *= Math.Pow(2, matchDamageMultiplier.Count);
  63.         damage /= Math.Pow(2, matchDamageDivision.Count);
  64.  
  65.         return damage;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement