Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _03Problem_NetherRealms
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> demons = Console.ReadLine().Split(',').Select(x => x.Trim()).OrderBy(x => x).ToList();
- string healthPattern = @"[^\d\+\-\\\/\*\.]";
- string damagePattern = @"((-?\d+(\.\d+)?))";
- string mathSymbolPatten = @"[\/*]";
- for (int i = 0; i < demons.Count; i++)
- {
- MatchCollection hpRegex = Regex.Matches(demons[i], healthPattern);
- MatchCollection dmgRegex = Regex.Matches(demons[i], damagePattern);
- MatchCollection mathSymbolRegex = Regex.Matches(demons[i], mathSymbolPatten);
- long totalHealth = 0;
- decimal totalDamage = 0M;
- foreach (Match letter in hpRegex)
- {
- totalHealth += letter.Value[0];
- }
- foreach (Match number in dmgRegex)
- {
- totalDamage += decimal.Parse(number.Value);
- }
- foreach (var mathSymbol in mathSymbolRegex)
- {
- if (mathSymbol.ToString().Equals("/"))
- {
- totalDamage /= 2;
- }
- else if (mathSymbol.ToString().Equals("*"))
- {
- totalDamage *= 2;
- }
- }
- Console.WriteLine($"{demons[i]} - {totalHealth} health, {totalDamage:0.00} damage");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement