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.RegularExpressions;
- namespace AshesOfRoses
- {
- public class StartUp
- {
- public static void Main(string[] args)
- {
- const string pattern = @"^Grow\s*<([A-Z][a-z]*)>\s<([a-zA-Z0-9]*)>\s([0-9]+)$";
- var regex = new Regex(pattern);
- var input = Console.ReadLine();
- var regions = new SortedDictionary<string,SortedDictionary<string,long>>();
- while (input!= null&& !input.Equals("Icarus, Ignite!"))
- {
- var match = regex.Match(input);
- if (match.Success)
- {
- long amount;
- var hasParsed = long.TryParse(match.Groups[3].Value, out amount);
- if (hasParsed&&amount<int.MaxValue)
- {
- if (!regions.ContainsKey(match.Groups[1].Value))
- {
- regions.Add(match.Groups[1].Value,new SortedDictionary<string, long>());
- }
- if (!regions[match.Groups[1].Value].ContainsKey(match.Groups[2].Value))
- {
- regions[match.Groups[1].Value].Add(match.Groups[2].Value,0);
- }
- regions[match.Groups[1].Value][match.Groups[2].Value] += amount;
- }
- }
- input = Console.ReadLine();
- }
- foreach (var region in regions.OrderByDescending(p=>p.Value.Values.Sum()))
- {
- Console.WriteLine(region.Key);
- foreach (var color in region.Value.OrderBy(p=>p.Value))
- {
- Console.WriteLine($"*--{color.Key} | {color.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement