Advertisement
Guest User

Untitled

a guest
Nov 1st, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 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 int Health { get; set; }
  14. public double Damage { get; set; }
  15. }
  16.  
  17. class Program
  18. {
  19. static void Main()
  20. {
  21. string[] demons = Console.ReadLine().Split(',').Select(x => x.Trim()).ToArray();
  22. List<Demon> res = new List<Demon>();
  23. Regex check = new Regex(@"-?\d+\.?\d*");
  24. Demon dem = new Demon();
  25. foreach (var demon in demons)
  26. {
  27. dem = new Demon();
  28. int health = 0;
  29. foreach (var item in demon.Where(x => !char.IsDigit(x) && x != '+' && x != '-' && x != '*' && x != '/' && x != '.'))
  30. {
  31. health += (int)item;
  32. }
  33. double damage = 0.0;
  34. foreach (Match match in check.Matches(demon))
  35. {
  36. damage += double.Parse(match.Value);
  37. }
  38. foreach (var item in demon)
  39. {
  40. if (item== '*')
  41. {
  42. damage *= 2;
  43. }
  44. else if(item== '/')
  45. {
  46. damage /= 2;
  47. }
  48. }
  49. dem.Health = health;
  50. dem.Damage = damage;
  51. dem.Name = demon;
  52. res.Add(dem);
  53. }
  54.  
  55. foreach (var item in res.OrderBy(x=>x.Name))
  56. {
  57. Console.WriteLine("{0} - {1} health, {2:f2} damage",item.Name,item.Health,item.Damage);
  58. }
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement