The usage of C composite function
- 2020-05-17 06:10:09
- OfStack
As follows:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Class1
{
static string[] str = { "A", "B", "C", "D", "E" };
static void Main()
{
Dictionary<string, int> dic = new Dictionary<string, int>();
// Adds an array element to dic
for (int i = 0; i < str.Length; i++)
{
dic.Add(str[i], i);
}
GetDic(dic);
Console.ReadLine();
}
static void GetDic(Dictionary<string, int> dd)
{
Dictionary<string, int> dic = new Dictionary<string, int>();
// Mainly to catch AB,AC,AD,AE, And then you start from BC . BD This principle is used dd The ratio of the key to the corresponding index in the array dd In the value Large scale combination
foreach (KeyValuePair<string, int> kk in dd)
{
for (int i = kk.Value + 1; i < str.Length; i++)
{
Console.WriteLine(kk.Key + str[i]);
dic.Add(kk.Key + str[i], i);
}
}
// recursive
if (dic.Count > 0) GetDic(dic);
}
}
}
The results of
AB
AC
AD
AE
BC
BD
BE
CD
CE
DE
ABC
ABD
ABE
ACD
ACE
ADE
BCD
BCE
BDE
CDE
ABCD
ABCE
ABDE
ACDE
BCDE
ABCDE