Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _04.CubicAssault
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class CubicAssault
- {
- public static void Main()
- {
- var inputLine = Console.ReadLine();
- var result = new SortedDictionary<string, SortedDictionary<string, long>>();
- while (inputLine != "Count em all")
- {
- var inputParams = inputLine.Split(new[] { '-', '>' });
- var region = inputParams[0].Trim();
- var type = inputParams[1].Trim();
- var numberAsString = inputParams[2].Trim();
- var number = long.Parse(numberAsString);
- if (!result.ContainsKey(region))
- {
- result.Add(region, new SortedDictionary<string, long>());
- result[region].Add("Black", 0L);
- result[region].Add("Red", 0L);
- result[region].Add("Green", 0L);
- }
- result[region][type] += number;
- var isMoreThanMilion = result[region][type] / 1000000L;
- if (type != "Black" && isMoreThanMilion > 0)
- {
- if (type == "Green")
- {
- result[region][type] = 0;
- result[region]["Red"] += isMoreThanMilion;
- isMoreThanMilion = result[region]["Red"] / 1000000L;
- if (isMoreThanMilion > 0)
- {
- result[region]["Red"] = 0;
- result[region]["Black"] += isMoreThanMilion;
- }
- }
- else
- {
- result[region][type] = 0;
- result[region]["Black"] += isMoreThanMilion;
- }
- }
- inputLine = Console.ReadLine();
- }
- foreach (var region in result.OrderByDescending(x => x.Value["Black"]).ThenBy(x => x.Key.Length))
- {
- Console.WriteLine(region.Key);
- foreach (var type in region.Value.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"-> {type.Key} : {type.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement