Problem: Use your most hands-on programming language to implement a function that prints all possible combinations of the characters in a string. These combinations range in length from one to the length of the string. Two combinations that differ only in ordering of the characters ARE the same combination.  In other words, “12” and “31” are different combinations from the input string “123”, but “21 is the same as “12”.For example, if we use “wxyz” as parameter for Combination(“wxyz”) the function will print outw
x
y
z
wx
wy
wz
xy
xz
yz
wxy
wxz
wyz
xyz
wxyz /// <summary>
/// 本函数不支持重复字符组合
/// </summary>
/// <param name="paCombString"></param>
/// <returns></returns>
public static ArrayList GetCombinationCount(string paCombString)
{
//定义一个list变量作为返回值
ArrayList result = new ArrayList(); char[] chrArray=paCombString.ToCharArray(); //先把字符串的所有单个字符放进来
result.AddRange(chrArray); if(chrArray.Length>1)
{
int count=result.Count;
int m=0;
while(true)
{
//外层循环是指每次都拿这个字符串里的单个字符和result里的结果进行连接
//如:输入a,b,c,d,那么result被初始化为:a,b,c,d,那我就用a去和a,b,c,d进行连接,如果目标字符包含这个单个字符就进行下一次循环连接
//这样就可以得到,a,b,c,d,ab,ac,ad,bc,bd,cd,然后再用a,b,c,d分别去和刚得到的两码字符串进行连接
//就得到:abc,abd,acd,bcd,同理向下直到找完所有组合!
for (int k=0;k<chrArray.Length;k++)
{
for(int j=m;j<count;j++)
{
if(result[j].ToString().IndexOf(result[k].ToString())==-1)
{
result.Add(result[k].ToString()+result[j].ToString());
}
else
{
m++;
}
}
m++;
}
count=result.Count; //当计算的个数达到2的字符串长度次方-1个时,就退出循环
if(count==(int)(Math.Pow((double)2,(double)chrArray.Length)-1))
{
break;
}
}
}
return result;
}