标签:style os io strong for 2014 ar div
题目:输入一个字符串,求出其所有的组合。比如字符串abc,其组合为:a、b、c、ab 、ac、 bc 、abc。代码:
/*
字符串组合
by Rowandjj
2014/8/8
*/
#include<iostream>
#include<math.h>
using namespace std;
void func(char *pStr)
{
int len = strlen(pStr);//字符串长度
int num = pow(2,len);//对应的二进制的上限
for(int i = 1; i < num; i++)
{
for(int j = 0; j < len; j++)
{
if((i>>j)&1)//依次右移,并判断该位是否为1
{
cout<<pStr[len-j-1];//是1就输出对应位置的值
}
}
cout<<endl;
}
}
int main()
{
char str[] = "abc";
func(str);
return 0;
}
标签:style os io strong for 2014 ar div
原文地址:http://blog.csdn.net/chdjj/article/details/38437953