ソリューションオプション:
// C# program to print all // possible strings of length k using System; class GFG { // The method that prints all // possible strings of length k. // It is mainly a wrapper over // recursive function printAllKLengthRec() static void printAllKLength(char[] set, int k) { int n = set.Length; for (int j=0; j<=k; j++) { printAllKLengthRec(set, "", n, j); } } // The main recursive method // to print all possible // strings of length k static void printAllKLengthRec(char[] set, String prefix, int n, int k) { // Base case: k is 0, // print prefix if (k == 0) { Console.WriteLine(prefix); return; } // One by one add all characters // from set and recursively // call for k equals to k-1 for (int i = 0; i < n; ++i) { // Next character of input added String newPrefix = prefix + set[i]; // k is decreased, because // we have added a new character printAllKLengthRec(set, newPrefix, n, k - 1); } } // Driver Code static public void Main () { Console.WriteLine("First Test"); char[] set1 = {'a', 'b'}; int k = 3; printAllKLength(set1, k); Console.WriteLine("\nSecond Test"); char[] set2 = {'a', 'b', 'c', 'd'}; k = 1; printAllKLength(set2, k); } }