字符数组的所有子集

in C/C++ with 0 comment

#include "stdafx.h"
#include "iostream"
#include <cmath>
using namespace std;

//输出子集
void getSubset(char list[]) {
	int length = strlen(list);
	cout << length;
	for (int i = 0; i <=pow(2,length)-1; i++) {
		for (int j = 0; j <length; j++) {
			if ((i >> j) & 1) {
				cout << list[j];
			}
		}
		cout << " ";
	}
	cout << endl;
}

int main()
{
	char list[] = "abcdef";
	getSubset(list);
	
	system("pause");
    return 0;
}