Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using System.Linq;
- namespace _5._Nether_Realms
- {
- class Program
- {
- static void Main(string[] args)
- {
- //string[] names = Console.ReadLine()
- // .Split(new char[] { ' ', ',' , '\t'}, StringSplitOptions.RemoveEmptyEntries);
- var dict = new Dictionary<string, Dictionary<string, double>>();
- string[] names = Regex
- .Split(Console.ReadLine(), @"\s*,\s*")
- .OrderBy(x=>x)
- .ToArray();
- int countOfNames = names.Length;
- for (int i = 0; i < countOfNames; i++)
- {
- string currentName = names[i];
- double health = 0;
- double damage = 0;
- Regex healthPattern = new Regex(@"[^0-9+\-*\/.]");
- Regex damagePattern = new Regex(@"(\+|-)?\d+\.?\d*");
- Regex mdSymbolsPattern = new Regex(@"[*\/]");
- MatchCollection matchesHealth = healthPattern.Matches(currentName);
- foreach (Match symbol in matchesHealth)
- {
- health += char.Parse(symbol.Value);
- }
- MatchCollection matchesDamage = damagePattern.Matches(currentName);
- foreach (Match item in matchesDamage)
- {
- damage += double.Parse(item.Value);
- }
- MatchCollection mdSymbols = mdSymbolsPattern.Matches(currentName);
- foreach (Match symbol in mdSymbols)
- {
- if (symbol.Value == "*")
- {
- damage *= 2;
- }
- else
- {
- damage /= 2;
- }
- }
- if (!dict.ContainsKey(currentName))
- {
- dict[currentName] = new Dictionary<string, double>();
- dict[currentName]["health"] = health;
- dict[currentName]["damage"] = damage;
- }
- Console.WriteLine($"{currentName} - {health} health, {damage:F2} damage");
- }
- //foreach (var kvp in dict
- // .OrderBy(x => x.Key))
- //{
- // int counter = 1;
- // foreach (var item in kvp.Value)
- // {
- // if (counter == 1)
- // {
- // Console.Write($"{kvp.Key} - {item.Value} health, ");
- // }
- // else if (counter == 2)
- // {
- // Console.WriteLine($"{item.Value:F2} damage");
- // }
- // counter++;
- // }
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment