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. iBrand 产品工具包:Laravel Database Logger

    iBrand 社交新零售电商产品从2016年9月启动至今,已经趋于稳定,而且已经初步得到市场的检验,特别能抗住电商中秒杀时高并发的交易场景. 接下来我们团队会逐步开源一些正在使用的工具和解决方案,并且 ...

  2. 学web前端开发有前途吗

    web前端开发现在如此火爆,可以说是引领了IT培训行业的一个潮流,那么web前端开发都要学些什么知识呢?为什么这么火有前途吗?现在行业很需要这种人才吗?还是大家盲目跟风,随大流,下面小编对web前端做 ...

  3. caffe︱深度学习参数调优杂记+caffe训练时的问题+dropout/batch Normalization

    一.深度学习中常用的调节参数 本节为笔者上课笔记(CDA深度学习实战课程第一期) 1.学习率 步长的选择:你走的距离长短,越短当然不会错过,但是耗时间.步长的选择比较麻烦.步长越小,越容易得到局部最优 ...

  4. 第3章 PCI总线的数据交换

    PCI Agent设备之间,以及HOST处理器和PCI Agent设备之间可以使用存储器读写和I/O读写等总线事务进行数据传送.在大多数情况下,PCI桥不直接与PCI设备或者HOST主桥进行数据交换, ...

  5. mysql数据库字符集编码查看以及设置

      show variables like %char% character_set_client     | gb2312                           character_s ...

  6. FusionCharts for Flex的属性和事件

    FusionCharts for Flex的属性和事件 1.Properties(属性) (1)FCChartType (2)FCDataURL (3)FCDataXML (4)FCDebugMode ...

  7. 个性化WinPE封装方法----制作过程需要了解的“命令”

    1.在现有的Windows7条件下,自动在E盘建立mywinpe文件夹,设置 Windows PE 构建环境,并保存到E:\mywinpe下 copype.cmd x86 E:\mywinpe 2.将 ...

  8. 嵌入式Linux基于framebuffer的jpeg格式本地LCD屏显示

    在基于Linux的视频监控采集系统中,摄像头采集到的一帧视频图像数据一般都是经过硬件自动压缩成jpeg格式的,然后再保存到摄像头设备的缓冲区.如果要把采集到的jpeg格式显示在本地LCD屏上,由于我们 ...

  9. No bean named 'sessionFactory' is defined

    1.错误描述 严重:Servlet service() for servlet default threw exception . org.springframework.beans.factory. ...

  10. 第十篇:Map/Reduce 工作机制分析 - 数据的流向分析

    前言 在MapReduce程序中,待处理的数据最开始是放在HDFS上的,这点无异议. 接下来,数据被会被送往一个个Map节点中去,这也无异议. 下面问题来了:数据在被Map节点处理完后,再何去何从呢? ...