List<List<string>> res = Generate("abcdefghijklmnopqrstuvwxyz0123456789-");
Console.WriteLine("Count = " + res.Count);
for (int i = 0; i < res.Count; i++)
{
Console.WriteLine(res[i]);
}
public static List<List<string>> Generate(string word)
{
List<List<string>> result = new List<List<string>>();
List<string> dList = new List<string>();
foreach (char i in word)
{
dList.Add(i.ToString());
}
result.Add(dList);
int a = 0;
do
{
result.Add(GetNext(word, result[a]));
a++;
} while (a < result.Count);
return result;
}
private static List<string> GetNext(string word, List<string> list)
{
List<string> dList = new List<string>();
int count = list.Count;
for (int i = 0; i < word.Length; i++)
{
for (int a = 0; a < count; a++)
{
dList.Add(word[i].ToString() + list[a]);
}
}
return dList;
}
输出格式:
a,b,c,……
aa,ab,ac,……
ba,bb,bc,……
ca,cb,cc,……
aaa,aab,aac,……aba,abb,abc,……aca,acb,acc,……
baa,bab,bac,……bba,bbb,bbc,……bca,bcb,bcc,……
caa,cab,cac,……cba,cbb,cbc,……cca,ccb,ccc,……
aaaa,aaab,aaac,……aaba,aabb,aabc,……aaca,aacb,aacc,……
网页抓取、网络爬虫效果图: