GetAllPossbileCombinations With C#
(ZT)
……………………………………..
tatic int counter = 0;
static string[] m_Data = { "A", "B", "C", "D", "E" };
static List<String> finalresult = new List<string>();
static void Main(string[] args)
{
Dictionary<string, int> dic = new Dictionary<string, int>();
for (int i = 0; i < m_Data.Length; i++)
{
counter++;
// Console.WriteLine(counter.ToString() + " " + m_Data[i]);//如果不需要打印单元素的组合,将此句注释掉
finalresult.Add(m_Data[i]);
dic.Add(m_Data[i], i);
}
GetString(dic);
Console.WriteLine("Final List Count:" + finalresult.Count.ToString());
foreach(string s in finalresult )
{
Console.WriteLine(s);
}
}
static void GetString(Dictionary<string, int> dd)
{
Dictionary<string, int> dic = new Dictionary<string, int>();
foreach (KeyValuePair<string, int> kv in dd)
{
for (int i = kv.Value + 1; i < m_Data.Length; i++)
{
counter++;
// Console.WriteLine(counter.ToString() + " "+kv.Key + m_Data[i]);
finalresult.Add(kv.Key +" " +m_Data[i]);
dic.Add(kv.Key + " " + m_Data[i], i);
}
}
if (dic.Count > 0) GetString(dic);
}
}
……………………………….
0 Comments:
Post a Comment
<< Home