日期:2014-05-20 浏览次数:20849 次
StringBuilder sb = new StringBuilder(); string Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int[] p = new int[26];//字符索引 int Length = 3 - 1;//字符串的长度 int i = Length; p[i] = -1; //初始化sb变量 int a =0; while (a++ <= Length) sb.Append("A"); //遍历解空间 while (i > -1) { if (p[i] == 25) { sb.Remove(i, 1); i--; continue; } else { p[i] = p[i] + 1; sb[i] = Table[p[i]]; if (i < Length) { i++; p[i] = -1; sb.Append(" "); continue; } } Console.WriteLine ( sb.ToString() ); }