UVa 146 ID Codes: Dictionary order

Source: Internet
Author: User
Tags time limit

146-id Codes

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=82

It is 2084 and the Brother has finally arrived, albeit a century late. In order to exercise greater control over it citizens and thereby to counter a chronic breakdown in Vernment decides on a radical measure--all citizens are to have a tiny microcomputer surgically implanted into their left WR Ists. This computer would contains all sorts of personal information as as as a transmitter which'll allow people ' s movements To is logged and monitored by a computer. (A desirable side effect of this process are that it would shorten the dole queue for plastic surgeons.)

A essential component of each computer is a unique identification code, consisting of up to-characters drawn from The lower case letters. The set of characters for no given the code is chosen somewhat haphazardly. The complicated way in which the ' code is ' imprinted into the chip makes it's much easier ' for the ' manufacturer to produce code s which are rearrangements of the other codes than to produce new codes with a different selection of letters. Thus, once a set of letters has been chosen all possible codes derivable from it are used to before the set.

For example, suppose it are 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 are are listed from the top to bottom in the alphabetic order. Among all codes the generated with this set of characters, which is codes appear consecutively in the.

Write a program to assist in the issuing of 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 are 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 is terminated by 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

ABAACB
Cbbaa
#

Sample output

Ababac
No successor

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Complete code:

/*0.012s*/
    
#include <cstdio>  
#include <cstring>  
#include <algorithm>  
using namespace Std;  
    
Char str[55];  
    
int main ()  
{while  
    (gets (str), str[0]!= ' # ')  
        puts (next_permutation (str, str + strlen (str))? STR: "No succes Sor ");  
    return 0;  
}

Author: csdn Synapse7

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.