Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _02_03_NetherRealms
- {
- class NetherRealms
- {
- static void Main(string[] args)
- {
- // 100% from the very first try!
- Regex healthPattern = new Regex(@"[^0-9-.,\+*\/]");
- Regex damagePattern = new Regex(@"-?\d+(\.\d+)?");
- Regex multiplyPattern = new Regex(@"[*\/]");
- string[] input = Console.ReadLine()
- .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
- .OrderBy(x => x)
- .ToArray();
- foreach (string word in input)
- {
- MatchCollection letters = healthPattern.Matches(word);
- long health = 0L;
- foreach (Match match in letters)
- {
- health += (int)char.Parse(match.Value);
- }
- MatchCollection numbers = damagePattern.Matches(word);
- double damage = 0.0;
- foreach (Match match in numbers)
- {
- damage += double.Parse(match.Value);
- }
- MatchCollection multipliers = multiplyPattern.Matches(word);
- foreach (Match match in multipliers)
- {
- switch (match.Value)
- {
- case "*":
- damage *= 2;
- break;
- case "/":
- damage /= 2.0;
- break;
- }
- }
- Console.WriteLine($"{word} - {health} health, {damage:F2} damage");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment