Advertisement
simonradev

MapDistrict

Jun 15th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. namespace MapDistricts
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.    
  7.     public class Program
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             long popultionDistrict = long.MinValue;
  12.             Console.ReadLine()
  13.                    .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  14.                    .Select(s =>
  15.                    {
  16.                        string[] tokens = s.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  17.                        return new KeyValuePair<string, long>(tokens[0], long.Parse(tokens[1]));
  18.                    })
  19.                    .GroupBy(k => k.Key)
  20.                    .ToDictionary(key => key.Key, value => value.Select(s => s.Value).ToArray())
  21.                    .Where(v => v.Value.Sum() > (popultionDistrict == long.MinValue ? popultionDistrict = long.Parse(Console.ReadLine()) : popultionDistrict))
  22.                    .OrderByDescending(p => p.Value.Sum())
  23.                    .ToList()
  24.                    .ForEach(kvp => Console.WriteLine($"{kvp.Key}: {string.Join(" ", kvp.Value.OrderByDescending(x => x).Take(5))}"));
  25.  
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement