Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace NetherRealm
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] demonNames = Console.ReadLine()
  15.                 .Split(new char[] {' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  16.  
  17.             Dictionary<string, demon> demons = new Dictionary<string, demon>();
  18.  
  19.             foreach (var demonName in demonNames)
  20.             {
  21.                 string pattern = @"(\-|\+)*([0-9]+\.)*[0-9]+";
  22.                 Regex regex = new Regex(pattern);
  23.  
  24.                 MatchCollection matchCollection = regex.Matches(demonName);
  25.  
  26.                 double sum = 0;
  27.  
  28.                 foreach (Match match in matchCollection)
  29.                 {
  30.                     double num = double.Parse(match.ToString());
  31.                     sum += num;
  32.                 }
  33.  
  34.                 string pattern1 = @"\*";
  35.                 Regex regex1 = new Regex(pattern1);
  36.  
  37.                 MatchCollection matchCollection1 = regex1.Matches(demonName);
  38.  
  39.                 foreach (Match match1 in matchCollection1)
  40.                 {
  41.                         sum *= 2;
  42.                 }
  43.  
  44.                 string pattern3 = @"\/";
  45.                 Regex regex3 = new Regex(pattern3);
  46.  
  47.                 MatchCollection matchCollection3 = regex3.Matches(demonName);
  48.  
  49.                 foreach (Match match3 in matchCollection3)
  50.                 {
  51.                     sum /= 2;
  52.                 }
  53.  
  54.                 int sumHealth = 0;
  55.  
  56.                 string pattern2 = @"[^\d\.\+\-\*\/]+";
  57.                 Regex regex2 = new Regex(pattern2);
  58.  
  59.                 MatchCollection matchCollection2 = regex2.Matches(demonName);
  60.  
  61.                 foreach (Match match2 in matchCollection2)
  62.                 {
  63.                     char[] symbols = match2.ToString().ToCharArray();
  64.  
  65.                     foreach (var symbol in symbols)
  66.                     {
  67.                         int num = symbol;
  68.                         sumHealth += num;
  69.                     }
  70.                 }
  71.  
  72.                 demon participant = new demon();
  73.                 participant.damage = sum;
  74.                 participant.health = sumHealth;
  75.  
  76.                 demons.Add(demonName, participant);
  77.             }
  78.  
  79.             foreach (var demonName in demons.OrderBy(x => x.Key))
  80.             {
  81.                
  82.                 Console.WriteLine("{0} - {1} health, {2:f2} damage", demonName.Key, demonName.Value.health, demonName.Value.damage);
  83.             }
  84.         }
  85.     }
  86.  
  87.     public class demon
  88.     {
  89.         public double health { get; set; }
  90.         public double damage { get; set; }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement