Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. var names = Console.ReadLine().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray().OrderBy(x=>x);
  11. var list = new List<string>();
  12.  
  13. foreach (var name in names)
  14. {
  15. list.Clear();
  16. var rg = new Regex(@"(?<=\d|\w)(-\d+.(?=\d)\d*|-\d+)|(\d+.(?=\d)\d*|\d+)");
  17. var matches = rg.Matches(name);
  18. foreach (Match match in matches)
  19. {
  20. var a = match.Groups[1].Value;
  21. var a1 = match.Groups[2].Value;
  22. if(a != string.Empty)
  23. {
  24. list.Add(a);
  25. }
  26. else
  27. {
  28. list.Add(a1);
  29. }
  30. }
  31. var letterSum = 0;
  32. var digitSum = list.Select(double.Parse).Sum();
  33. for (int i = 0; i < name.Length; i++)
  34. {
  35. if (char.IsLetter(name[i]))
  36. {
  37. letterSum += name[i];
  38. }
  39. else if (name[i] =='/')
  40. {
  41. digitSum /=2;
  42. }
  43. else if (name[i] == '*')
  44. {
  45. digitSum *= 2;
  46. }
  47. }
  48. Console.WriteLine("{0} - {1} health, {2:f2} damage", name, letterSum, digitSum);
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement