Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MapDistricts
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- public static void Main(string[] args)
- {
- long popultionDistrict = long.MinValue;
- Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(s =>
- {
- string[] tokens = s.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
- return new KeyValuePair<string, long>(tokens[0], long.Parse(tokens[1]));
- })
- .GroupBy(k => k.Key)
- .ToDictionary(key => key.Key, value => value.Select(s => s.Value).ToArray())
- .Where(v => v.Value.Sum() > (popultionDistrict == long.MinValue ? popultionDistrict = long.Parse(Console.ReadLine()) : popultionDistrict))
- .OrderByDescending(p => p.Value.Sum())
- .ToList()
- .ForEach(kvp => Console.WriteLine($"{kvp.Key}: {string.Join(" ", kvp.Value.OrderByDescending(x => x).Take(5))}"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement