Advertisement
Prohause

Ashes of Roses

Jun 19th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace AshesOfRoses
  7. {
  8. public class StartUp
  9. {
  10. public static void Main(string[] args)
  11. {
  12. const string pattern = @"^Grow\s*<([A-Z][a-z]*)>\s<([a-zA-Z0-9]*)>\s([0-9]+)$";
  13. var regex = new Regex(pattern);
  14. var input = Console.ReadLine();
  15. var regions = new SortedDictionary<string,SortedDictionary<string,long>>();
  16.  
  17. while (input!= null&& !input.Equals("Icarus, Ignite!"))
  18. {
  19. var match = regex.Match(input);
  20.  
  21. if (match.Success)
  22. {
  23. long amount;
  24. var hasParsed = long.TryParse(match.Groups[3].Value, out amount);
  25. if (hasParsed&&amount<int.MaxValue)
  26. {
  27. if (!regions.ContainsKey(match.Groups[1].Value))
  28. {
  29. regions.Add(match.Groups[1].Value,new SortedDictionary<string, long>());
  30. }
  31. if (!regions[match.Groups[1].Value].ContainsKey(match.Groups[2].Value))
  32. {
  33. regions[match.Groups[1].Value].Add(match.Groups[2].Value,0);
  34. }
  35. regions[match.Groups[1].Value][match.Groups[2].Value] += amount;
  36. }
  37. }
  38. input = Console.ReadLine();
  39. }
  40. foreach (var region in regions.OrderByDescending(p=>p.Value.Values.Sum()))
  41. {
  42. Console.WriteLine(region.Key);
  43. foreach (var color in region.Value.OrderBy(p=>p.Value))
  44. {
  45. Console.WriteLine($"*--{color.Key} | {color.Value}");
  46. }
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement