#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
int main(){
int set[5]={1,4,2,6,8};
// int x;
// x=6;
// x>>=1;
// cout<<x<<endl;
int length = sizeof(set)/sizeof(set[0]);
int flag=0;
long n = (long) pow((float) 2, length);
for (int i = 0; i < n; i++) {
flag=0;
cout<<"{";
int temp = i;
for (int j = 0; j < length; j++) {
if ((temp & 1) == 1) {
if(flag==1) cout<<",";
cout<<set[j];
flag=1;
// if (j < length - 1) {
// cout<<",";
// }
}
temp = temp >> 1;
}
cout<<"}";
}
}
求一个集合的所有子集(lintCode 17.子集)
最新推荐文章于 2021-10-17 20:18:05 发布