Can any genius out there turn this code from generating permutation to generating combination?
        Posted  
        
            by mark
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by mark
        
        
        
        Published on 2010-04-29T15:01:22Z
        Indexed on 
            2010/04/29
            15:07 UTC
        
        
        Read the original article
        Hit count: 378
        
#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);
}
        © Stack Overflow or respective owner