Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7. namespace _05.Nether_Realms
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string inputString = Console.ReadLine();
  14. string[] inputArray = inputString.Split(',');
  15. for (int i = 0; i < inputArray.Length; i++)
  16. {
  17. inputArray[i] = inputArray[i].Trim();
  18. }
  19.  
  20. var dictionary = new Dictionary<string, List<double>>();
  21.  
  22. for (int i = 0; i < inputArray.Length; i++)
  23. {
  24. string healthString = string.Empty;
  25. double healthDouble = 0;
  26. string damageString = string.Empty;
  27. double damageDouble = 0;
  28. string patternHealth = @"[^\+\-\*\/\.0-9]";
  29. string patternDamage = @"([0-9\-\+\.]+)";
  30. string patternAsteriskOrSlash = @"(\*|\/)";
  31.  
  32. MatchCollection charsHealth = Regex.Matches(inputArray[i], patternHealth);
  33. foreach (Match item in charsHealth)
  34. {
  35. healthString += item.Value;
  36. }
  37. for (int j = 0; j < healthString.Length; j++)
  38. {
  39. healthDouble += (double)healthString[j]; // HEALTH INTEGER OUTPUT
  40. }
  41.  
  42. MatchCollection charsDamage = Regex.Matches(inputArray[i], patternDamage);
  43. if (charsDamage.Count == 0)
  44. {
  45. damageDouble = 0;
  46. }
  47. else
  48. {
  49. foreach (Match itemm in charsDamage)
  50. {
  51. damageDouble += double.Parse(itemm.ToString());
  52. }
  53. }
  54.  
  55. MatchCollection charsAsterisk = Regex.Matches(inputArray[i], patternAsteriskOrSlash);
  56. foreach (Match asteriskMatch in charsAsterisk)
  57. {
  58. if (asteriskMatch.Value == "*")
  59. {
  60. damageDouble = damageDouble * 2;
  61. }
  62. else if (asteriskMatch.Value == "/")
  63. {
  64. damageDouble = damageDouble / 2;
  65. }
  66. }
  67.  
  68. List<double> newList = new List<double>();
  69. newList.Add(healthDouble);
  70. newList.Add(damageDouble);
  71.  
  72. dictionary.Add(inputArray[i], newList);
  73. }
  74.  
  75. dictionary = dictionary.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
  76.  
  77. foreach (var item in dictionary)
  78. {
  79. Console.WriteLine($"{item.Key} - {item.Value[0]} health, {item.Value[1]:F2} damage");
  80. }
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement