DJColdBrain

03. Nether Realms

Jul 4th, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 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 _03.Nether_Realms
  9. {
  10. class Demon
  11. {
  12. public string Name { get; set; }
  13. public int Healt { get {
  14.  
  15. //var healt = Regex.Matches(Name, "[^0-9-+*/.]");
  16. var healt = Regex.Matches(Name, @"[^\d\.\+\-\*\/\s\,]");
  17. int h = 0;
  18. char[] hel = new char[healt.Count];
  19. for (int i = 0; i < healt.Count; i++)
  20. {
  21. hel[i] = healt[i].ToString().ToCharArray()[0];
  22. }
  23. for (int i = 0; i < hel.Length; i++)
  24. {
  25. h += hel[i];
  26. }
  27. return h;
  28. }
  29. }
  30. public float Dmg { get {
  31. Regex lineSplitter = new Regex(@"([+-]?[\d]*[.]*[\d]*)");
  32. // Regex lineSplitter = new Regex(@"[\+\-]*[0-9.]+[0-9]*");
  33. var dmg = lineSplitter.Matches(Name);
  34. List<float> floats = new List<float>();
  35. string[] ddd = new string[dmg.Count];
  36. for (int i = 0; i < dmg.Count; i++)
  37. {
  38. ddd[i] = dmg[i].ToString();
  39. }
  40. ddd = ddd.Where(x => x != string.Empty).ToArray();
  41. for (int i = 0; i < ddd.Length; i++)
  42. {
  43. floats.Add(float.Parse(ddd[i]));
  44. }
  45.  
  46.  
  47. var multiplayers =Regex.Matches(Name, "[*/]");
  48. float damage = floats.Sum();
  49. for (int i = 0; i < multiplayers.Count; i++)
  50. {
  51. if (multiplayers[i].ToString() == "*")
  52. {
  53. damage *= 2;
  54. }
  55. else if(multiplayers[i].ToString() == "/")
  56. {
  57. damage /= 2;
  58. }
  59. }
  60. return damage;
  61. }
  62. }
  63.  
  64.  
  65. public Demon (string name)
  66. {
  67. this.Name = name;
  68. }
  69.  
  70.  
  71.  
  72. }
  73.  
  74. class Program
  75. {
  76. static void Main(string[] args)
  77. {
  78. string[] demons = Console.ReadLine().Split(',').Select(x => x.Trim()).OrderBy(x => x).ToArray();
  79. for (int i = 0; i < demons.Length; i++)
  80. {
  81. Demon demon = new Demon(demons[i]);
  82. Console.WriteLine("{0} - {1} health, {2:f2} damage", demon.Name, demon.Healt, demon.Dmg);
  83. }
  84. }
  85. }
  86. }
Add Comment
Please, Sign In to add comment