whitestarrr

Untitled

Oct 25th, 2016
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 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 NetherRealms
  9. {
  10. class Demon
  11. {
  12. public string Name { get; set; }
  13. public decimal Damage { get; set; }
  14. public decimal Health { get; set; }
  15. }
  16. class NetherRealms
  17. {
  18. static void Main(string[] args)
  19. {
  20. string input = Console.ReadLine();
  21. string numberPattern = @"([-+])?([0-9]*\.[0-9]+|[0-9]+)";
  22. string namePattern = @"[^/*.+-0,1,2,3,4,5,6,7,8,9]";
  23. string[] demons = input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  24. List<Demon> demonBook = new List<Demon>();
  25. for (int j = 0; j < demons.Length; j++)
  26. {
  27. string currentDemon = demons[j];
  28. MatchCollection numberMatches = Regex.Matches(currentDemon, numberPattern);
  29. MatchCollection nameMatches = Regex.Matches(currentDemon, namePattern);
  30. decimal damage = 0;
  31. int health = 0;
  32.  
  33. StringBuilder name = new StringBuilder();
  34. foreach (Match match in numberMatches)
  35. {
  36. string value = match.Groups[1].Value.ToString();
  37.  
  38. if (value == "-")
  39. {
  40. damage -= decimal.Parse(match.Groups[2].Value);
  41. }
  42. else if (value == "+")
  43. {
  44. damage += decimal.Parse(match.Groups[2].Value);
  45. }
  46. else
  47. {
  48. damage += decimal.Parse(match.Groups[2].Value);
  49. }
  50.  
  51. }
  52.  
  53. foreach (Match item in nameMatches)
  54. {
  55. name.Append(item);
  56. }
  57.  
  58. for (int i = 0; i < name.Length; i++)
  59. {
  60. health += name[i];
  61. }
  62.  
  63.  
  64. for (int i = 0; i < currentDemon.Length; i++)
  65. {
  66. if (currentDemon[i] == '*')
  67. {
  68. damage *= 2;
  69. }
  70. else if ((currentDemon[i] == '/'))
  71. {
  72. damage /= 2;
  73. }
  74.  
  75. }
  76.  
  77. if (!demonBook.Any(x => x.Name == currentDemon))
  78. {
  79. Demon demon = new Demon();
  80. demon.Name = demons[j];
  81. demon.Health = health;
  82. demon.Damage = damage;
  83. demonBook.Add(demon);
  84. }
  85.  
  86. }
  87. var orderedDemonBook = demonBook.OrderBy(x => x.Name);
  88. foreach (var demon in orderedDemonBook)
  89. {
  90. Console.WriteLine($"{demon.Name} - {demon.Health} health, {demon.Damage:f2} damage");
  91. }
  92. }
  93. }
  94. }
Add Comment
Please, Sign In to add comment