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.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace _05.Nether_Realms
- {
- class Program
- {
- static void Main(string[] args)
- {
- string inputString = Console.ReadLine();
- string[] inputArray = inputString.Split(',');
- for (int i = 0; i < inputArray.Length; i++)
- {
- inputArray[i] = inputArray[i].Trim();
- }
- var dictionary = new Dictionary<string, List<double>>();
- for (int i = 0; i < inputArray.Length; i++)
- {
- string healthString = string.Empty;
- double healthDouble = 0;
- string damageString = string.Empty;
- double damageDouble = 0;
- string patternHealth = @"[^\+\-\*\/\.0-9]";
- string patternDamage = @"([0-9\-\+\.]+)";
- string patternAsteriskOrSlash = @"(\*|\/)";
- MatchCollection charsHealth = Regex.Matches(inputArray[i], patternHealth);
- foreach (Match item in charsHealth)
- {
- healthString += item.Value;
- }
- for (int j = 0; j < healthString.Length; j++)
- {
- healthDouble += (double)healthString[j]; // HEALTH INTEGER OUTPUT
- }
- MatchCollection charsDamage = Regex.Matches(inputArray[i], patternDamage);
- if (charsDamage.Count == 0)
- {
- damageDouble = 0;
- }
- else
- {
- foreach (Match itemm in charsDamage)
- {
- damageDouble += double.Parse(itemm.ToString());
- }
- }
- MatchCollection charsAsterisk = Regex.Matches(inputArray[i], patternAsteriskOrSlash);
- foreach (Match asteriskMatch in charsAsterisk)
- {
- if (asteriskMatch.Value == "*")
- {
- damageDouble = damageDouble * 2;
- }
- else if (asteriskMatch.Value == "/")
- {
- damageDouble = damageDouble / 2;
- }
- }
- List<double> newList = new List<double>();
- newList.Add(healthDouble);
- newList.Add(damageDouble);
- dictionary.Add(inputArray[i], newList);
- }
- dictionary = dictionary.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
- foreach (var item in dictionary)
- {
- Console.WriteLine($"{item.Key} - {item.Value[0]} health, {item.Value[1]:F2} damage");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement