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 Nether_Realms
- {
- class Demon
- {
- public string Name { get; set; }
- public double Health { get; set; }
- public double Damage { get; set; }
- }
- class Program
- {
- static void Main()
- {
- string[] nameDemons = Console.ReadLine()
- .Trim()
- .Split(',')
- .Select(x => x.Trim())
- .ToArray();
- if (nameDemons.Length==0)
- {
- return;
- }
- List<Demon> demons = new List<Demon>();
- int health = 0;
- double resultDamage = 0;
- string patternForHealth = @"[^0-9\+-\.*/]";
- string patternForDamage = @"[\d+-.]+";
- string patternAction = @"[*/]";
- for (int i = 0; i < nameDemons.Length; i++)
- {
- Demon demon = new Demon();
- Match matchHealth = Regex.Match(nameDemons[i], patternForHealth);
- Match matchDamage = Regex.Match(nameDemons[i], patternForDamage);
- Match matchAction = Regex.Match(nameDemons[i], patternAction);
- while (matchHealth.Success)
- {
- int codeSymbol = Convert.ToChar(matchHealth.ToString());
- health += codeSymbol;
- matchHealth = matchHealth.NextMatch();
- }
- while (matchDamage.Success)
- {
- double currentDamage = double.Parse(matchDamage.ToString());
- resultDamage += currentDamage;
- matchDamage = matchDamage.NextMatch();
- }
- while (matchAction.Success)
- {
- char ch = Convert.ToChar(matchAction.ToString());
- if (ch=='/')
- {
- resultDamage /= 2;
- }
- else if (ch=='*')
- {
- resultDamage *= 2;
- }
- matchAction = matchAction.NextMatch();
- }
- demon.Name = nameDemons[i];
- demon.Health = health;
- demon.Damage = resultDamage;
- demons.Add(demon);
- health = 0;
- resultDamage = 0;
- }
- var sortDemons = demons.OrderBy(x => x.Name);
- foreach (var result in sortDemons)
- {
- Console.WriteLine("{0} - {1} health, {2:F2} damage"
- ,result.Name,result.Health,result.Damage);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement