Advertisement
stanevplamen

03.01.04.ColorBallsArange

Jul 1st, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. // n! / (k1! * k2! * ...)
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Numerics;
  6.  
  7. class ColorBallsArange
  8. {
  9.     static void Main()
  10.     {
  11.         string input = Console.ReadLine(); //"RYYRYBY";
  12.         Dictionary<char, int> ballsDict = new Dictionary<char, int>();
  13.         int temp = 0;
  14.         char currentKey = ' ';
  15.         for (int i = 0; i < input.Length; i++)
  16.         {
  17.             bool exists = false;
  18.             foreach (KeyValuePair<char, int> kvp in ballsDict)
  19.             {
  20.                 if (kvp.Key == input[i])
  21.                 {
  22.                     exists = true;
  23.                     temp = kvp.Value + 1;
  24.                     currentKey = kvp.Key;
  25.                 }
  26.             }
  27.             if (exists == false)
  28.             {
  29.                 ballsDict.Add(input[i], 1);
  30.             }
  31.             else if (exists == true)
  32.             {
  33.                 ballsDict[input[i]] = temp;
  34.             }
  35.         }
  36.         BigInteger nominator = 1;
  37.         BigInteger denominator = 1;
  38.         int counter = 1;
  39.         foreach (KeyValuePair<char, int> kvp in ballsDict)
  40.         {
  41.             temp = kvp.Value;
  42.             for (int i = 1; i <= temp; i++)
  43.             {
  44.                 denominator = denominator * i;
  45.             }
  46.             counter++;
  47.         }
  48.  
  49.         for (int i = 1; i <= input.Length ; i++)
  50.         {
  51.              nominator = nominator * i;
  52.         }
  53.  
  54.         BigInteger result = nominator / denominator;
  55.         Console.WriteLine(result);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement