ID Codes
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 6143 |
|
Accepted: 3685 |
Description
It is 2084 and the year of Big Brother have finally arrived, albeit a century late. In order to exercise greater control over it citizens and thereby to counter a chronic breakdown in law and order, the Go Vernment decides on a radical measure--all citizens is to has a tiny microcomputer surgically implanted in their left WR Ists. This computer would contains all sorts of the personal information as well as a transmitter which would allow people ' s movements To is logged and monitored by a central computer. (A desirable side effect of this process are that it'll shorten the dole queue for plastic surgeons.)
An essential component of each computer would be a unique identification code, consisting of up to characters drawn from The lower case letters. The set of characters for any given code is chosen somewhat haphazardly. The complicated on which the code is imprinted into the chip makes it much easier for the manufacturer to produce code s which is rearrangements of other codes than to produce new codes with a different selection of letters. Thus, once a set of letters have been chosen all possible codes derivable from it is used before changing the set.
For example, suppose it was decided that a code would contain exactly 3 occurrences of ' a ', 2 of ' B ' and 1 of ' C ', then thre E of the allowable codes under these conditions are:
ABAABC ABAACB Ababac
These three codes is listed from the top to the bottom in alphabetic order. Among all codes generated with the This set of characters, these codes appear consecutively in this order.
Write a program to assist in the issuing of these identification codes. Your program would accept a sequence of no more than-lower case letters (which may contain repeated characters) and Prin T the successor code if one exists or the message ' No successor ' if the given code is the last in the sequence for that SE T of characters.
Input
Input would consist of a series of lines each containing a string representing a code. The entire file would be terminated to a line consisting of a single #.
Output
Output would consist of one line for each code read containing the successor code or the words ' No successor '.
Sample Input
abaacbcbbaa#
Sample Output
ABABACNO successor
Test instructions: A string of subsequent strings, that is, a string of dictionary ordering the next one!
The use of next_permutation:
Header files: #include <algorithm>
Next_permutation (Array,array+n);
#include <iostream> #include <string.h> #include <algorithm>using namespace Std;int main () {char s[100 ];while (cin>>s) {int N=strlen (s), if (strcmp (S, "#") = = 0) break ; if (Next_permutation (s, S + N)) cout<<s<<endl; else cout<< "No successor\n";} return 0;}
POJ 1146 ID Codes