Advertisement
stoianpp

Grishko

Jan 19th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. class Program
  6. {
  7.     static char[] result;
  8.     static HashSet<string> count = new HashSet<string>();
  9.     static int totalLength;
  10.  
  11.     static void Main()
  12.     {
  13.         StringBuilder letters = new StringBuilder(Console.ReadLine());
  14.         totalLength = letters.Length;
  15.         result = new char[totalLength];
  16.         int loop = 0;
  17.         Filling(letters, loop);
  18.         Console.WriteLine(count.Count);
  19.     }
  20.  
  21.     static void Filling(StringBuilder letters, int loop)
  22.     {
  23.         if (loop >= totalLength)
  24.         {
  25.             count.Add(String.Join("",result));
  26.             return;
  27.         }
  28.        
  29.         for (int i = 0; i < letters.Length; i++)
  30.         {
  31.             result[loop] = letters[i];
  32.             while (loop - 1 >= 0 && result[loop] == result[loop - 1])
  33.             {
  34.                 i++;
  35.                 if (i == letters.Length) return;
  36.                 result[loop] = letters[i];
  37.             }
  38.             StringBuilder lettersToGo = new StringBuilder(letters.Length);
  39.             for (int g = 0; g < letters.Length; g++)
  40.             {
  41.                 if (g != i) lettersToGo.Append(letters[g]);
  42.             }
  43.             Filling(lettersToGo, loop + 1);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement