Will this work? I tried my solution with some test cases.

# include <stdio.h>

void printCombinations( char buffer[], int bI, char string[], int sI, int
length ) ;

int main( void )
{
    char str[1024], buf[1024] ;
    int i, j, length ;

    scanf( "%s", str ) ;
    for( length = 0 ; str[length] ; ++length )
        ;

    printCombinations( buf, 0, str, 0, length ) ;

    getchar( ) ;
    getchar( ) ;

    return 0 ;
}

void printCombinations( char buffer[], int bI, char string[], int sI, int
length )
{
    if( sI >= length )
        return ;

    while( sI < length )
    {
        buffer[ bI ] = string[ sI++ ] ;
        buffer[ bI + 1 ] = '\0' ;
        printf( "%s\n", buffer ) ;
        printCombinations( buffer, bI + 1, string, sI, length ) ;
    }
}


On 21/10/2007, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> Q) You are given a string in which the characters are sorted. Write a
> program to generate all the combinations of characters such that only
> the lexicographically lowest permutation of every combination is
> printed. (ie. If the string is "abcd" then "ab" is a valid
> combination, but "ba" is not). Further, the combinations generated
> must themselves be in dictionary order.
>
> Example:
> For the string "ABC", the combinations are:
> A
> AB
> ABC
> AC
> B
> BC
> C
> You may write the output to standard output.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to