Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace Orders
- {
- class Program
- {
- static void Main(string[] args)
- {
- string heltsPattern = @"[^0-9+\-*\/.]";
- Regex heltsRegex = new Regex(heltsPattern);
- string digitPattern = @"-?\d+\.?\d*";
- Regex digitRegex = new Regex(digitPattern);
- string operatorPattern = @"[*\/]";
- Regex operatorRegex = new Regex(operatorPattern);
- string[] demonNames = Regex.Split(Console.ReadLine(), @"\s*,\s*").OrderBy(x => x).ToArray();
- for (int i = 0; i < demonNames.Length; i++)
- {
- string currentDemon = demonNames[i];
- int currentHelts = 0;
- MatchCollection heltsSymbols = heltsRegex.Matches(currentDemon);
- foreach (Match symbol in heltsSymbols)
- {
- currentHelts += char.Parse(symbol.Value);
- }
- double baseDamage = 0;
- MatchCollection digitMatch = digitRegex.Matches(currentDemon);
- foreach (Match number in digitMatch)
- {
- baseDamage += double.Parse(number.Value);
- }
- MatchCollection operatorMatch = operatorRegex.Matches(currentDemon);
- foreach (Match operatorr in operatorMatch)
- {
- string ooper = operatorr.Value;
- if (ooper == "*")
- {
- baseDamage *= 2;
- }
- else
- {
- baseDamage /= 2;
- }
- }
- Console.WriteLine($"{currentDemon} - {currentHelts} health, {baseDamage:f2} damage");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement