poj-1146 ID codes
Description
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
Output
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的更多相关文章
- poj 1146 ID Codes (字符串处理 生成排列组合 生成当前串的下一个字典序排列 【*模板】 )
ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6229 Accepted: 3737 Descript ...
- POJ 1146 ID Codes 用字典序思想生成下一个排列组合
ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7644 Accepted: 4509 Descript ...
- POJ 1146 ID Codes (UVA146)
// 求下一个排列// 如果已经是最后一个排列// 就输出 No Successor// stl 或 自己写个 生成排列 我测试了下 两个速率是一样的.只是代码长度不同 /* #include < ...
- (组合数学3.1.1.1)POJ 1146 ID Codes(字典序法)
/* * POJ_1146.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...
- ACM POJ 1146 ID Codes
题目大意:输入一个字符串.输出它的下一个字典序排列. 字典序算法思想: 1.从右向左寻找字符串找出第一个a[i]<a[i+1]的位置i; 2.从右向左找出第一个大于a[i]的元素a[j]; 3. ...
- 1146 ID Codes
题目链接: http://poj.org/problem?id=1146 题意: 给定一个字符串(长度不超过50), 求这个字符串的下一个字典序的字符串, 如果已经是最大字典序, 那么输出 " ...
- 【水一发next_permutation】poj 1146——ID Codesm
来源:点击打开链接 求字典序下一位,没有直接输出没有.全排列函数秒水过. #include <iostream> #include <algorithm> #include & ...
- POJ 1146:ID Codes
ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6281 Accepted: 3769 Description ...
- uva146 ID codes
Description It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In or ...
- Brute Force & STL --- UVA 146 ID Codes
ID Codes Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&a ...
随机推荐
- java 集合框架(四)Set
一.概述 Set是一种没有重复元素的集合,它所有的方法都是直接继承自Collection接口,并且添加了一个对重复元素的限制.Set要求强化了equals和hashCode两个方法,以使Set集合可以 ...
- 使用java实现阿里云消息队列简单封装
一.前言 最近公司有使用阿里云消息队列的需求,为了更加方便使用,本人用了几天时间将消息队列封装成api调用方式以方便内部系统的调用,现在已经完成,特此记录其中过程和使用到的相关技术,与君共勉. 现在阿 ...
- Cramfs、JFFS2、YAFFS2全面对比
由 于嵌入式系统自身存在一些特殊要求使得一些传 统的文件系统 (如FAT.EXT2等) 并不十分适合.专 用的嵌入式文件系统应有一些自身的特性如文件系统 面对的储存介质特殊性.文件系统应具有的跨 ...
- python实现简单排序算法
算法 递归两个特点: 调用自身 有穷调用 计算规模越来越小,直至最后结束 用装饰器修饰一个递归函数时会出现问题,这个问题产生的原因是递归的函数也不停的使用装饰器.解决方法是,只让装饰器调用一次即可,那 ...
- 版本控制工具--svn和git的使用(一) -----版本控制的好处以及分类
版本控制工具 版本控制VCS(Version Control Systems)是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.这个系统可以自动帮我们备份文件的每一次更改,并且可以 ...
- mybatis的动态增删改查
1.动态SQL片段 通过SQL片段达到代码复用 <!-- 动态条件分页查询 --> <sql id="sql_count"> select count(*) ...
- Tomcat下使用C3P0配置JNDI数据源(在项目的META-INF目录下创建context.xml的文件)
一.C3P0下载 C3P0下载地址:http://sourceforge.net/projects/c3p0/files/?source=navbar 下载完成之后得到一个压缩包
- MyISAM和InnoDB索引实现区别
首先来讲MyISAM: MyISAM引擎使用B+Tree作为索引结构,叶节点的data域存放的是数据记录的地址.下图是MyISAM索引的原理图: 这里设表一共有三列,假设我们以Col1为主键,则上图是 ...
- [SHOI2012]随机树
[SHOI2012]随机树 题目大意( 网址戳我! ) 随机树是一颗完全二叉树,初始状态下只有一个节点. 随机树的生成如下:每次随机选择一个叶子节点,扩展出两个儿子. 现在给定一个正整数\(n\)(\ ...
- 【洛谷3047】[USACO12FEB]附近的牛Nearby Cows
题面 题目描述 Farmer John has noticed that his cows often move between nearby fields. Taking this into acc ...