UVa146
来源:互联网 发布:部门间数据共享协议 编辑:程序博客网 时间:2024/05/24 00:11
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 and Output
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 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.
二、利用next_permutation()函数,直接求下一个序列,该函数返回boolean类型,若有下一个序列,则返回ture,若没有,则返回false.
AC代码:
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;char a[10];int main(){ int b; while(scanf("%s",a)&&a[0]!='#') { b=strlen(a); if(next_permutation(a,a+b)) printf("%s\n",a); else printf("No Successor\n"); } return 0;}遇到的问题:提交的时候,总是显示runtime error.将数组定义为全局就AC了.
- uva146
- uva146
- uva146
- uva146
- UVA146
- UVa146
- uva146
- UVa146 ID Codes (排列)
- uva146 ID Codes
- uva146(排序)
- UVA146 ID Codes
- UVA146 ID codes
- uva146 ID codes
- uva146--求下一个排列
- uva146(简单题)-全排列
- UVA146生成可重集的下一个排列
- UVA146 POJ1146 ID Codes【全排列】
- 设计模式笔记--解释器模式
- DSP6678 以太网启动
- akka概念 学习笔记
- 文字不换行使用等于号
- RabbitMQ入门教程 For Java【3】 - Publish/Subscribe
- UVa146
- 【Unity Shader】浅析Unity shader中RenderType的作用及_CameraDepthNormalsTexture
- 【装载】hibernate的三种状态
- C6678 IBL NAND boot over I2C
- 《JS高级程序设计》读书笔记
- jvm判断对象是否存活
- 编辑距离-Levenshtein距离
- spring mvc快速搭建——Hello World!
- 基于LBS的兴趣点查询