sans-hubris
07-04-2002, 03:59 PM
I have some problems from an intercollegiate ACM competition.
I'll list the first one, and once someone solves it, I'll list the next one.
A manufacturer wishes to encode the products it produces with unique codes expressed as a sequence of up to 32 uppercase letters. Every occurence of a particular product model will be encoded using the same number and the same group of letters, but in different permutations, of course.
For example a simple product code might include just the three letters A, B, and C. No more than six of this particular model product could be labeled with a code, however, since there are only six different codes that could be produced using A, B, and C (specifically ABC, ACB, BAC, BCA, CAB, and CBA.)
Some groups of letters from which codes are produced might include duplicates. For example, suppose the group included A, A, and B. The only codes that could be produced using this group are AAB, ABA, and BAA.
The manufacturer wants a program to aid in the generation of the product codes. Specifically, given an existing product code, determine and display the next sequential product code. The sequential ordering of product codes is naturally based on alphabetic ordering.
Input
The input will contain multiple cases. The input for each case is a single line containing between 1 and 32 uppercase letters immediately followed by the end of line character. The line following the last case will contain only a single end of line character.
Output
For each input case, display the next sequential product code on a line by itself, if one exists. If there is no next sequential code (that is, the input code is the last in the sequence of codes that can be created using the given group of letters), then display the message "*** No Successor ***".
Sample Input Expected Output
ACB BAC
ABCA ACAB
ZYXCAB ZYXCBA
ZYXCBA *** No Successor ***
<Blank line>
NB: vBulletin seems to like putting extra blank lines in the code boxes, FYI.
I'll list the first one, and once someone solves it, I'll list the next one.
A manufacturer wishes to encode the products it produces with unique codes expressed as a sequence of up to 32 uppercase letters. Every occurence of a particular product model will be encoded using the same number and the same group of letters, but in different permutations, of course.
For example a simple product code might include just the three letters A, B, and C. No more than six of this particular model product could be labeled with a code, however, since there are only six different codes that could be produced using A, B, and C (specifically ABC, ACB, BAC, BCA, CAB, and CBA.)
Some groups of letters from which codes are produced might include duplicates. For example, suppose the group included A, A, and B. The only codes that could be produced using this group are AAB, ABA, and BAA.
The manufacturer wants a program to aid in the generation of the product codes. Specifically, given an existing product code, determine and display the next sequential product code. The sequential ordering of product codes is naturally based on alphabetic ordering.
Input
The input will contain multiple cases. The input for each case is a single line containing between 1 and 32 uppercase letters immediately followed by the end of line character. The line following the last case will contain only a single end of line character.
Output
For each input case, display the next sequential product code on a line by itself, if one exists. If there is no next sequential code (that is, the input code is the last in the sequence of codes that can be created using the given group of letters), then display the message "*** No Successor ***".
Sample Input Expected Output
ACB BAC
ABCA ACAB
ZYXCAB ZYXCBA
ZYXCBA *** No Successor ***
<Blank line>
NB: vBulletin seems to like putting extra blank lines in the code boxes, FYI.