Can any genius out there turn this code from generating permutation to generating combination?
- by mark
#include <string>
int main(int,char**)
{
std::string default_str = "12345";
int perm=1, digits=default_str.size();
for (int i=1;i<=digits;perm*=i++);
for (int a=0;a<perm;a++)
{
std::string avail=default_str;
for (int b=digits,div=perm;b>0; b--)
{
div/=b;
int index = (a/div)%b;
printf("%c", avail[index] );
avail.erase(index,1) ;
}
printf("\n");
}
printf("permutations:%d\n",perm);
while(1);
}