anilak

Featuring with Grisko ver.2

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