Advertisement
YavorGrancharov

Nether_Realms

Nov 3rd, 2017
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Nether_Realms
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string patternOne = @"([-|+]?[0-9\.]*[0-9])";
  13.  
  14.             string patternTwo = @"([A-Za-z]+)";
  15.  
  16.             string input = Console.ReadLine();
  17.  
  18.             string[] tokens = input
  19.                 .Split(new char[] { ' ', ',', '\t', '\n' },
  20.                 StringSplitOptions.RemoveEmptyEntries);
  21.  
  22.             List<string> demons = new List<string>();
  23.             foreach (var entry in tokens)
  24.             {
  25.                 demons.Add(entry);
  26.             }
  27.  
  28.             double damage = 0.0;
  29.             double health = 0.0;
  30.             foreach (var demon in demons)
  31.             {
  32.                 MatchCollection nums = Regex.Matches(demon, patternOne);
  33.                
  34.                 MatchCollection letters = Regex.Matches(demon, patternTwo);
  35.  
  36.                 List<double> numStore = new List<double>();
  37.                 foreach (Match num in nums)
  38.                 {
  39.                     if (num.Success)
  40.                     {
  41.                         double converted = double.Parse(num.Value);
  42.                         numStore.Add(converted);
  43.                     }
  44.                 }
  45.  
  46.                 foreach (var num in numStore)
  47.                 {
  48.                     damage += num;
  49.                 }
  50.  
  51.                 if (demon.Contains('*'))
  52.                 {
  53.                     int count = input.Count(c => c == '*');
  54.                     damage *= count * 2;
  55.  
  56.                     if (demon.Contains('/'))
  57.                     {
  58.                         damage /= 2;
  59.                     }
  60.                 }
  61.  
  62.                 string concat = string.Empty;
  63.                 foreach (Match letter in letters)
  64.                 {
  65.                     if (letter.Success)
  66.                     {
  67.                         concat += letter.Value.ToString();
  68.                     }
  69.                 }
  70.  
  71.                 for (int i = 0; i < concat.Length; i++)
  72.                 {
  73.                     health += concat[i];
  74.                 }
  75.             }
  76.  
  77.             foreach (var demon in demons)
  78.             {
  79.                 Console.WriteLine("{0} - {1} health, {2:F2} damage", demon, health, damage);
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement