Advertisement
MZlatev

Untitled

Dec 2nd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 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 _5._NetherRealms
  8. {
  9. class NetherRealms
  10. {
  11. static void Main()
  12. {
  13. string healthPattern = @"[^0-9+\-*\/.]";
  14. Regex healthRegex = new Regex(healthPattern);
  15.  
  16. string digitPattern = @"-?\d+\.?\d*";
  17. Regex digitRegex = new Regex(digitPattern);
  18.  
  19. string operatorPattern = @"[*\/]";
  20. Regex operatorRegex = new Regex(operatorPattern);
  21.  
  22.  
  23. string[] demonNames = Regex
  24. .Split(Console.ReadLine(), @"\s*,\s*")
  25. .OrderBy(x => x)
  26. .ToArray();
  27.  
  28. for (int i = 0; i < demonNames.Length; i++)
  29. {
  30. string currentDemon = demonNames[i];
  31.  
  32. int currentHealth = 0;
  33.  
  34. MatchCollection healthSymbols = healthRegex.Matches(currentDemon);
  35.  
  36. foreach (Match symbol in healthSymbols)
  37. {
  38. currentHealth += char.Parse(symbol.Value);
  39. }
  40.  
  41. MatchCollection digitMatch = digitRegex.Matches(currentDemon);
  42.  
  43. double baseDamage = 0;
  44.  
  45. foreach (Match number in digitMatch)
  46. {
  47. baseDamage += double.Parse(number.Value);
  48. }
  49.  
  50. MatchCollection operatorMatch = operatorRegex.Matches(currentDemon);
  51.  
  52.  
  53. foreach (Match operatorr in operatorMatch)
  54. {
  55. string @operator = operatorr.Value;
  56.  
  57. if (@operator == "*")
  58. {
  59. baseDamage *= 2;
  60. }
  61.  
  62. else
  63. {
  64. baseDamage /= 2;
  65. }
  66. }
  67.  
  68. Console.WriteLine($"{currentDemon} - {currentHealth} health, {baseDamage:f2} damage");
  69.  
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement