Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 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. using System.Threading.Tasks;
  7.  
  8. namespace Nether_Realms
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. var demons = Console.ReadLine().Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  15. var demonBook = new SortedDictionary<string, string>();
  16. foreach(var demon in demons)
  17. {
  18. var health = GetHealth(demon);
  19. var damage = GetDamage(demon);
  20.  
  21. demonBook[demon] = $"{demon} - {health} health, {damage:f2} damage";
  22. }
  23.  
  24. foreach(var demon in demonBook)
  25. {
  26. Console.WriteLine(demon.Value);
  27. }
  28. }
  29.  
  30. private static object GetDamage(string demon)
  31. {
  32. Regex pattern = new Regex(@"(\-|\+|)[0-9]+(\.|[0-9]|)([0-9]+|)");
  33.  
  34. var damageItems = pattern.Matches(demon);
  35. double damage = 0;
  36. foreach (var item in damageItems)
  37. {
  38. damage += double.Parse(item.ToString());
  39. }
  40.  
  41. Regex multipliers = new Regex(@"[\*\/]");
  42.  
  43. var muliplierItems = multipliers.Matches(demon);
  44.  
  45. foreach(var item in muliplierItems)
  46. {
  47. foreach(var mult in item.ToString())
  48. {
  49. if (mult.Equals('/'))
  50. {
  51. damage /= 2;
  52. }
  53. else
  54. {
  55. damage*=2;
  56. }
  57. }
  58. }
  59. return damage;
  60. }
  61.  
  62. private static object GetHealth(string demon)
  63. {
  64. Regex pattern = new Regex(@"[^0-9\+\-\*\/\.]");
  65.  
  66. var healthItems = pattern.Matches(demon);
  67. var health = 0;
  68. foreach(var item in healthItems)
  69. {
  70. foreach(var hp in item.ToString())
  71. {
  72. health += (int)hp;
  73. }
  74. }
  75.  
  76. return health;
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement