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 Tech_Module_23_10_Exam
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] input = Console.ReadLine()
- .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
- .OrderBy(a => a)
- .ToArray();
- List<Demon> demons = new List<Demon>();
- foreach (var demonName in input)
- {
- double damage = CalculateDamage(demonName);
- int health = CalculateHealth(demonName);
- Demon newDemon = new Demon()
- {
- Name = demonName,
- Damage = damage,
- Health = health
- };
- demons.Add(newDemon);
- }
- demons = demons.OrderBy(a => a.Name).ToList();
- foreach (var demon in demons)
- {
- Console.WriteLine("{0} - {1} health, {2:f2} damage", demon.Name, demon.Health, demon.Damage);
- }
- }
- private static int CalculateHealth(string demonData)
- {
- Regex healthRegex = new Regex(@"[^0-9+\-*/\.]");
- MatchCollection matches = healthRegex.Matches(demonData);
- int health = 0;
- foreach (Match m in matches)
- {
- health += m.Value[0]; // every match is only one char
- }
- return health;
- }
- private static double CalculateDamage(string demonData)
- {
- Regex damageRegex = new Regex(@"[+-]?\d+(\.\d+)?");
- double damage = 0;
- foreach (var number in damageRegex.Matches(demonData))
- {
- damage += double.Parse(number.ToString());
- }
- double multiplier = GetMultiplier(demonData);
- damage *= multiplier;
- return damage;
- }
- private static double GetMultiplier(string demonData)
- {
- double multiplier = 1;
- for (int i = 0; i < demonData.Length; i++)
- {
- if (demonData[i] == '*')
- {
- multiplier *= 2;
- }
- else if (demonData[i] == '/')
- {
- multiplier /= 2;
- }
- }
- return multiplier;
- }
- }
- class Demon
- {
- public string Name { get; set; }
- public double Damage { get; set; }
- public int Health { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement