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 NetherRealms
- {
- class Demon
- {
- public string Name { get; set; }
- public decimal Damage { get; set; }
- public decimal Health { get; set; }
- }
- class NetherRealms
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string numberPattern = @"([-+])?([0-9]*\.[0-9]+|[0-9]+)";
- string namePattern = @"[^/*.+-0,1,2,3,4,5,6,7,8,9]";
- string[] demons = input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- List<Demon> demonBook = new List<Demon>();
- for (int j = 0; j < demons.Length; j++)
- {
- string currentDemon = demons[j];
- MatchCollection numberMatches = Regex.Matches(currentDemon, numberPattern);
- MatchCollection nameMatches = Regex.Matches(currentDemon, namePattern);
- decimal damage = 0;
- int health = 0;
- StringBuilder name = new StringBuilder();
- foreach (Match match in numberMatches)
- {
- string value = match.Groups[1].Value.ToString();
- if (value == "-")
- {
- damage -= decimal.Parse(match.Groups[2].Value);
- }
- else if (value == "+")
- {
- damage += decimal.Parse(match.Groups[2].Value);
- }
- else
- {
- damage += decimal.Parse(match.Groups[2].Value);
- }
- }
- foreach (Match item in nameMatches)
- {
- name.Append(item);
- }
- for (int i = 0; i < name.Length; i++)
- {
- health += name[i];
- }
- for (int i = 0; i < currentDemon.Length; i++)
- {
- if (currentDemon[i] == '*')
- {
- damage *= 2;
- }
- else if ((currentDemon[i] == '/'))
- {
- damage /= 2;
- }
- }
- if (!demonBook.Any(x => x.Name == currentDemon))
- {
- Demon demon = new Demon();
- demon.Name = demons[j];
- demon.Health = health;
- demon.Damage = damage;
- demonBook.Add(demon);
- }
- }
- var orderedDemonBook = demonBook.OrderBy(x => x.Name);
- foreach (var demon in orderedDemonBook)
- {
- Console.WriteLine($"{demon.Name} - {demon.Health} health, {demon.Damage:f2} damage");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement