Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using System.Text;
- public class Program
- {
- public static void Main()
- {
- Dictionary<string,Dictionary<int,double>> nameHpDmg = new Dictionary<string,Dictionary<int,double>>();
- string[] names = Console.ReadLine().Split(new[] {',',' '},StringSplitOptions.RemoveEmptyEntries);
- foreach (string name in names)
- {
- int health =0;
- for (int i=0; i<name.Length; i++)
- {
- char curr = name[i];
- if (char.IsDigit(curr) || curr=='+' || curr=='-' || curr == '*' || curr=='/' || curr=='.')
- {
- continue;
- }
- else
- {
- health += (int) curr;
- }
- }
- string numsPattern = @"(\+|-)?(\d+(\.\d+)?)";
- double dmg = 0;
- if (Regex.IsMatch(name,numsPattern))
- {
- MatchCollection matches = Regex.Matches(name,numsPattern);
- foreach (Match match in matches)
- {
- double currMatch = double.Parse(match.Value);
- dmg+=currMatch;
- }
- }
- foreach (char symbol in name)
- {
- if (symbol == '*')
- {
- dmg*=2;
- }
- else if (symbol == '/')
- {
- dmg/=2.0;
- }
- }
- nameHpDmg.Add(name,new Dictionary<int,double>());
- nameHpDmg[name].Add(health,dmg);
- }
- foreach (var kvp in nameHpDmg.OrderBy(x=>x.Key))
- {
- string name = kvp.Key;
- foreach (var kvpValue in kvp.Value)
- {
- Console.WriteLine("{0} - {1} health, {2:f2} damage",name,kvpValue.Key,kvpValue.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment