Advertisement
anilak

Featuring with Grisko

Sep 15th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2.  
  3. class FeaturingWithGrisko
  4. {
  5.     static int combCount = 0;
  6.  
  7.     static int[] usedCount;
  8.  
  9.     static void GetComb(char[] comb, int start)
  10.     {
  11.         if (start >= comb.Length)
  12.         {
  13.             combCount++;
  14.             return;
  15.         }
  16.         for (int i = 0; i < usedCount.Length; i++)
  17.         {
  18.             if ((start == 0 || comb[start - 1] != (char)(i + 'a')) && usedCount[i] > 0)
  19.             {
  20.                 comb[start] = (char)(i + 'a');
  21.                 usedCount[i]--;
  22.                 GetComb(comb, start + 1);
  23.                 usedCount[i]++;
  24.             }
  25.         }
  26.     }
  27.  
  28.     static void Main()
  29.     {
  30.         usedCount = new int[26];
  31.         string letters = Console.ReadLine();
  32.         for (int i = 0; i < letters.Length; i++)
  33.         {
  34.             usedCount[letters[i] - 'a']++;
  35.         }
  36.         char[] comb = new char[letters.Length];
  37.         GetComb(comb, 0);
  38.         Console.WriteLine(combCount);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement