#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<vector<int> > Subsets(vector<int> s)
{
int n = s.size();
sort(s.begin(), s.end());
vector<vector<int> > subs;
queue<vector<int> > vQueue;
subs.push_back(vector<int>());
for (int i = 0; i < n; ++i)
vQueue.push(vector<int>(1,i));
while(!vQueue.empty())
{
vector<int>& subIndics = vQueue.front();
subs.push_back(vector<int>());
vector<int>& v = subs.back();
for (int i = 0; i < subIndics.size(); ++i)
v.push_back(s[subIndics[i]]);
int next = subIndics.back()+1;
subIndics.push_back(0);
for (int i = next; i < n; ++i)
{
subIndics.back() = i;
vQueue.push(subIndics);
}
vQueue.pop();
}
return subs;
}
void PrintVV(vector<vector<int> > v)
{
cout << '\n';
int size = 0;
for (int i = 0; i < v.size(); ++i)
{
cout << ++size << ':';
if (v[i].size() <= 0)
{
cout << "[empty]\n";
continue;
}
cout << '[';
for (int j = 0; j < v[i].size(); ++j)
cout << v[i][j] << ',';
cout << ']' << endl;
}
cout << endl;
}
vector<int> Array2Vector(int A[], int n)
{
vector<int> v;
for (int i = 0; i < n; ++i)
{
v.push_back(A[i]);
cout << A[i] << ',';
}
cout << endl;
return v;
}
int main(int argc, char** argv)
{
int A[] = {1, 3, 5, 7};
int n = sizeof(A)/sizeof(int);
vector<int> v = Array2Vector(A, n);
PrintVV(Subsets(v));
return 0;
}