poj-1146-全排列
来源:互联网 发布:Ping应用的端口号 编辑:程序博客网 时间:2024/06/06 01:25
ID Codes
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5336 Accepted: 3190
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:
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.
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
abaacbcbbaa#
Sample Output
ababacNo Successor
求该字符串的下一个排列,要是不存在的话,就输出No Successor
代码:
#include <iostream>#include <cstring>#include <string>#include <algorithm>using namespace std;int main() {int T;char str[103];while(scanf("%s", str) != EOF) {if(str[0] == '#') break;if(next_permutation(str, str + strlen(str)))printf("%s\n", str);elseprintf("No Successor\n");}return 0;}
- poj-1146-全排列
- Poj 1146 ID Codes + Poj 1833 排列 (全排列库函数)
- POJ 1146 字符串的下一个全排列
- POJ 1256 全排列
- 【poj】3187全排列
- POJ 1833 排列(全排列 STL)
- POJ 1256 全排列函数
- poj-1256 Anagram 全排列
- POJ 1731 下一个全排列
- poj 1294 全排列问题
- POJ 2718(STL全排列)
- poj 1256/1732/1833/1146 C++stl全排列
- POJ 1833 1146 1256 全排列系列 next_permutation函数
- POJ 1833下K个全排列
- poj 1731 字典序全排列
- POJ 1731 Orders(全排列)
- POJ 1731 Orders(全排列)
- POJ 1256 Anagram(next_permutation全排列)
- WinCE内存管理(三)
- WinCE内存管理(四)
- 可爱的汇编
- c++中的错误:error C2601: 'main' : local function definitions are illegal
- Android自适应不同分辨率或不同屏幕大小
- poj-1146-全排列
- Study Flex《自定义组件编写过程》
- WinCE嵌入式开发程序入门
- java防止SQL注入
- highcharts动态报表+Json用法
- WinCE中OEM适配层编程点滴之创建OAL
- 20130428记录一下go-sqlite的小问题
- 【总结】python和C语言(1)
- WinCE定制中的大内存支持与永久保存注册表