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 ...
随机推荐
- Android设置View抖动动画
在应用中,有时候我们要吸引用户去点击某些按钮,比如应用市场的推荐按钮,为了能够吸引用户主动点击而且不过分的打扰用户,最好的方法就是给我们想吸引用户注意的view添加一些抖动动画,比如这张图 这里我主要 ...
- R语言︱用excel VBA把xlsx批量转化为csv格式
笔者寄语:批量读取目前看到有以下几种方法:xlsx包.RODBC包.批量转化成csv后读入.本章来自博客:http://www.cnblogs.com/weibaar/p/4506144.html 在 ...
- 错误代码: 1111 Invalid use of group function
1.错误描述 1 queries executed, 0 success, 1 errors, 0 warnings 查询:update t_user_info t inner join t_pro_ ...
- Netty高可靠性设计:优化建议
尽管Netty的可靠性已经做得非常出色,但是在生产实践中还是发现了一些待优化点,本小节将进行简单说明.希望后续的版本中可以解决,当然用户也可以根据自己的实际需要决定自行优化. 1 发送队列容量上限控 ...
- JSON对象转换成JSON字符串
1.问题背景 有一个json对象,需要将其转换成json字符串 JSON.stringify(obj) 2.实现源码 <!DOCTYPE html PUBLIC "-//W3C//DT ...
- 玲珑杯#2.5 A-B
这个题解错了网上还没有题解 囧 = (i%2)? 1 : -1 = - * * *= m #include<bits/stdc++.h> using namespace std; type ...
- java基础之二分法查找
package p1; import java.util.*; public class Sortdob { public static void BubbleSort(int[] arr) { ...
- 【BZOJ4653】【NOI2016】区间(线段树)
[BZOJ4653][NOI2016]区间(线段树) 题面 BZOJ 题解 \(NOI\)良心送分题?? 既然是最大长度减去最小长度 莫名想到那道反复减边求最小生成树 从而求出最小的比值 所以这题的套 ...
- [SDOI2013]森林
主席树 离散化后 每个点储存从根到它的路径上的点权 新加边时直接用启发式合并,直接把size小的重构 询问时sum[u]+sum[v]-sum[lca]-sum[fa[lca]]来比较,在树上二分 L ...
- React-Native安装使用
先附上React-Native官方文档中文版:http://wiki.jikexueyuan.com/project/react-native/getting-started.html 好,接下来我们 ...