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;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace _03_netherRealms
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] names = Console.ReadLine()
- .Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- names = CheckNames(names);
- Dictionary<string, Dictionary<double, double>> fighters = new Dictionary<string, Dictionary<double, double>>();
- string numberPatter = @"([-+ ]?[\d]+[\.]?[\d]+)|\d";
- foreach (var name in names)
- {
- Match currNameMAtch = Regex.Match(name, @"[^\+\-\*\/0-9\.\s\,]");
- if (currNameMAtch.Success)
- {
- if (!fighters.ContainsKey(name))
- {
- fighters.Add(name, new Dictionary<double, double>());
- }
- long health = FighterHealth(name);
- double power = FighterPower(name, numberPatter);
- fighters[name][health] = power;
- }
- }
- var orderedFighters = fighters.OrderBy(f => f.Key);
- foreach (var fighter in orderedFighters)
- {
- Console.Write("{0} - ",fighter.Key);
- var stats = fighter.Value;
- foreach (var stat in stats)
- {
- Console.WriteLine($"{stat.Key} health, {stat.Value:F2} damage");
- }
- }
- }
- private static string[] CheckNames(string[] names)
- {
- List<string> newArray = new List<string>();
- foreach (var name in names)
- {
- if (!name.Contains(" "))
- {
- if (!name.Contains(","))
- {
- newArray.Add(name);
- }
- }
- }
- return newArray.ToArray();
- }
- private static double FighterPower(string name, string numberPatter)
- {
- double power = Regex.Matches(name, numberPatter)
- .Cast<Match>()
- .Select(n => n.Value)
- .Select(double.Parse)
- .ToArray()
- .Sum();
- string pattern = @"[*\/]?";
- string[] maths = Regex.Matches(name, pattern)
- .Cast<Match>()
- .Select(m => m.Value)
- .ToArray();
- foreach (var math in maths)
- {
- if(math == "*")
- {
- power *= 2;
- }
- else if(math == "/")
- {
- power /= 2;
- }
- }
- return power;
- }
- private static long FighterHealth(string name)
- {
- string[] currMatch = Regex.Matches(name, @"[^\+\-\*\/0-9\.\s\,]")
- .Cast<Match>()
- .Select(m => m.Value)
- .ToArray();
- long health = 0;
- for (int i = 0; i < currMatch.Length; i++)
- {
- health += char.Parse(currMatch[i]);
- }
- return health;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement