Uva-146-id Codes (enumeration arrangement)

Source: Internet
Author: User

UVA-146

ID Codes
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &%llu

Submit Status

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 three of the allowable codes under these conditions is:

      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 and Output

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 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

Source

Root:: Competitive programming:increasing The Lower Bound of programming contests (Steven & Felix Halim):: Chapter 2. Data Structures and Libraries:: Data structures with built-in Libraries:: STL algorithm
Root:: Competitive programming 2:this increases the lower bound of programming contests. Again (Steven & Felix Halim):: Data Structures and Libraries:: LINEAR data structures with built-in Libraries:: C + + STL algorithm (Java collections)
Root:: AOAPC i:beginning algorithm Contests (Rujia Liu):: Volume 3. Brute force:: Elementary Skills
Root:: Competitive programming 3:the New Lower Bound of programming contests (Steven & Felix Halim):: Data Structur Es and Libraries:: Linear Data structures with built-in Libraries:: C + + STL algorithm (Java collections)

Submit Status






Idea: The use of next_permutation in STL, to generate the current sequence in accordance with the dictionary order of the next sequence, for the string can also, for the re-set is OK, note: For this topic, if the current sequence is the last sequence, then output no successor, So before using next_permutation, you have to decide if it is the last sequence.


AC Code:




Update: The original next_permutation itself can determine whether to the last sequence in accordance with the dictionary order, so directly with the next_permutation can


AC Code:








Uva-146-id Codes (enumeration arrangement)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.