Advertisement
svetlai

Rabits

Nov 27th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. namespace Rabbits
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class ColouredBunniesCount
  8.     {
  9.         public static void Main()
  10.         {
  11.             int[] replies = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12.  
  13.             var colourGroupsCount = new Dictionary<int, int>();
  14.             var minBunnies = 0;
  15.  
  16.             foreach (var reply in replies)
  17.             {
  18.                 int colourGroup = reply + 1;
  19.  
  20.                 if (colourGroupsCount.ContainsKey(colourGroup))
  21.                 {
  22.                     colourGroupsCount[colourGroup]++;
  23.                 }
  24.                 else
  25.                 {
  26.                     colourGroupsCount.Add(colourGroup, 1);
  27.                 }
  28.             }
  29.  
  30.             foreach (var pair in colourGroupsCount)
  31.             {
  32.                 if (pair.Key > pair.Value)
  33.                 {
  34.                     minBunnies += pair.Key;
  35.                 }
  36.                 else
  37.                 {
  38.                     minBunnies += (int)Math.Ceiling((double)pair.Value / (pair.Key)) * (pair.Key);
  39.                 }
  40.             }
  41.  
  42.             Console.WriteLine(minBunnies);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement