Advertisement
AnastasiyaG

Untitled

Mar 21st, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6.  
  7. namespace _5._Nether_Realms
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] names = Console.ReadLine().Split(", ",StringSplitOptions.RemoveEmptyEntries);
  14. Dictionary<string, Dictionary<int, double>> result = new Dictionary<string, Dictionary<int, double>>();
  15.  
  16.  
  17. for (int i = 0; i < names.Length; i++)
  18. {
  19. string name = names[i];
  20. double damage = 0;
  21.  
  22. Regex regex = new Regex(@"([ |-]([0-9]+\.*[0-9]*)|[0-9]+)");
  23. MatchCollection matches = regex.Matches(name);
  24. foreach (Match item in matches)
  25. {
  26. damage += double.Parse(item.Value);
  27.  
  28. }
  29. char[] current = name.ToCharArray();
  30. int health = 0;
  31. bool oneLetter = false;
  32. for (int j = 0; j < current.Length; j++)
  33. {
  34. char now = current[j];
  35. if (now == ',' || now == ' ')
  36. { break; }
  37. if (char.IsLetter(now))
  38. { oneLetter = true;
  39. health += ((int)now); }
  40. if (now == '*')
  41. { damage *= 2; }
  42. if (now == '/')
  43. { damage /= 2; }
  44. }
  45. if (oneLetter == false)
  46. { break; }
  47. result[name] = new Dictionary<int, double>();
  48. result[name][health] = damage;
  49.  
  50.  
  51. }
  52. foreach (var item in result.OrderBy(x=>x.Key))
  53. {
  54.  
  55. foreach (var stuff in item.Value)
  56. {
  57. Console.WriteLine($"{item.Key} - { stuff.Key} health, {stuff.Value:f2} damage");
  58. }
  59.  
  60. }
  61.  
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement