Description

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

An essential component of each computer will be a unique identification code, consisting of up to 50 characters drawn from the 26 lower case letters. The set of characters for any given code is chosen somewhat haphazardly. The complicated way in which the code is imprinted into the chip makes it much easier for the manufacturer to produce codes which are rearrangements of 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 before changing the set.

For example, suppose it is decided that a code will contain exactly 3 occurrences of `a', 2 of `b' and 1 of `c', then three of the allowable 60 codes under these conditions are:

      abaabc

abaacb

ababac

These three codes are listed from top to bottom in alphabetic order. Among all codes generated with 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 will accept a sequence of no more than 50 lower case letters (which may contain repeated characters) and print the successor code if one exists or the message `No Successor' if the given code is the last in the sequence for that set of characters.

Input

Input will consist of a series of lines each containing a string representing a code. The entire file will be terminated by a line consisting of a single #.

Output

Output will 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
题目大意:
一组字符全排列,如果有下一个全排列则则输出 若无,则输出NO;
注意:
在STL中有个next_permutation(const *str,int length);函数。若有下一个全排列则返回true并生成下一个全排列,
反之返回false;
<a href="www.baidu.com">这儿</a>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int permutation(char str[],int length)
{ int j=0;
// sort(str,str+length); while(next_permutation(str,str+length))
{
for(int i=0;i<length;i++)
cout<<str[i]; cout<<endl;
j++;
break; }
return j;
}
int main ()
{
while(1)
{ char str[100];
cin>>str;
if(str[0]=='#')break;
int len=strlen(str);
int q=permutation(str,len);
if(!q)cout<<"No Successor"<<endl;
} return 0;
}

  

poj-1146 ID codes的更多相关文章

  1. poj 1146 ID Codes (字符串处理 生成排列组合 生成当前串的下一个字典序排列 【*模板】 )

    ID Codes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6229   Accepted: 3737 Descript ...

  2. POJ 1146 ID Codes 用字典序思想生成下一个排列组合

    ID Codes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7644   Accepted: 4509 Descript ...

  3. POJ 1146 ID Codes (UVA146)

    // 求下一个排列// 如果已经是最后一个排列// 就输出 No Successor// stl 或 自己写个 生成排列 我测试了下 两个速率是一样的.只是代码长度不同 /* #include < ...

  4. (组合数学3.1.1.1)POJ 1146 ID Codes(字典序法)

    /* * POJ_1146.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...

  5. ACM POJ 1146 ID Codes

    题目大意:输入一个字符串.输出它的下一个字典序排列. 字典序算法思想: 1.从右向左寻找字符串找出第一个a[i]<a[i+1]的位置i; 2.从右向左找出第一个大于a[i]的元素a[j]; 3. ...

  6. 1146 ID Codes

    题目链接: http://poj.org/problem?id=1146 题意: 给定一个字符串(长度不超过50), 求这个字符串的下一个字典序的字符串, 如果已经是最大字典序, 那么输出 " ...

  7. 【水一发next_permutation】poj 1146——ID Codesm

    来源:点击打开链接 求字典序下一位,没有直接输出没有.全排列函数秒水过. #include <iostream> #include <algorithm> #include & ...

  8. POJ 1146:ID Codes

    ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6281 Accepted: 3769 Description ...

  9. uva146 ID codes

    Description It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In or ...

  10. Brute Force & STL --- UVA 146 ID Codes

     ID Codes  Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&a ...

随机推荐

  1. Ubuntu 11.04安装arm-linux-gcc-4.4.3/arm-none-linux-gnueabi-gcc安装包

    准备工具和系统 arm-linux-gcc-4.4.3.tar.gz arm-linux-gcc-4.4.3下载地址: 下载在Linux公社的1号FTP服务器里,下载地址: FTP地址:ftp://w ...

  2. R语言与格式、日期格式、格式转化

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- R语言的基础包中提供了两种类型的时间数据,一类 ...

  3. Java之split()方法

    Java之split()方法 1.方法介绍 (1)public String[] split(String regex) 根据给定正则表达式的匹配拆分此字符串 (2)public String[] s ...

  4. Unhandled event loop exception GC overhead limit exceeded

    1.错误描述 java.lang.OutOfMemoryError: GC overhead limit exceeded at java.util.zip.ZipFile.<init>( ...

  5. Linux显示只显示目录文件

    Linux显示只显示目录文件 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ ls -l -d */ drwxr-xr-x 2 root root 4096 1 ...

  6. 如何给filter添加自定义接口

    .在Cfilter类的定义中实现Interface接口的函数的定义: //-----------------------Interface methods----------------------- ...

  7. MySQL中information_schema数据库的内容

    大家在安装或使用MYSQL时,会发现除了自己安装的数据库以外,还有一个information_schema数据库. information_schema数据库是做什么用的呢,使用WordPress博客 ...

  8. 启动就加载(三)initializingbean实现afterPropertiesSet方法

    TransactionTemplate,就直接以TransactionTemplate为入口开始学习. TransactionTemplate的源码如下: public class Transacti ...

  9. 异常-----web.xml文件报错 Multiple annotations found at this line: - cvc-complex-type.2.4.b: The content of element 'welcome-file-list' is not complete. One of '{"http://java.sun.c

    1,检查抬头是不是有问题. <?xml version="1.0" encoding="UTF-8"?><web-app version=&q ...

  10. JavaScript设计模式(3)-工厂模式

    工厂模式 1. 简单工厂 简单工厂:使用一个类或对象封装实例化操作 假如我们有个自行车商店类 BicycleShop,它提供了销售自行车的方法可以选择销售两类自行车 Speedster,Comfort ...