`
473687880
  • 浏览: 535237 次
文章分类
社区版块
存档分类
最新评论

ID Codes UVA 146

 
阅读更多



ID Codes

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

abaacb
cbbaa
#

Sample output

ababac
No Successor


这道题的一开始题意都没看懂,后来才发现就是求一个序列按照字典序的下一个排列组合。。。可以直接调用STL

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    string str;
    while(cin >> str)
    {
        if(str[0]=='#') break;
        int f=0;
        if(next_permutation(str.begin(), str.end()))
        {
            f=1;
            cout << str << endl;
        }
        if(!f) cout<< "No Successor" << endl;
    }
    return 0;
}

分享到:
评论

相关推荐

    SMD-codes Active SMD semiconductor components marking codes

    ### SMD-Codes:主动型SMD半导体组件的标记代码 #### 概述 随着电子产品技术的不断进步和发展,表面贴装技术(Surface Mount Technology,简称SMT)因其体积小、重量轻、易于自动化组装等优点,在电子产品的设计与...

    Algebraic codes for data transmission

    为此,纠错码(Error-Correcting Codes, ECC)作为一项关键的技术手段,在减少数据传输过程中的错误方面发挥着基础性的作用。本书《代数编码在数据传输中的应用》由伊利诺伊大学厄巴纳-香槟分校电气与计算机工程系...

    Error-Correcting Codes - Revised, 2nd Edition.djvu

    Error-Correcting Codes, by Professor Peterson, was originally published in 1961. Now, with E. J. Weldon, Jr., as his coauthor, Professor Peterson has extensively rewritten his material. The book ...

    Fountain codes论文

    Fountain codes are record-breaking sparse-graph codes for channels with erasures, such as the internet, where files are transmitted in multiple small packets, each of which is either received without ...

    github-recovery-codes.txt

    github-recovery-codes.txt

    C++ Codes C++ Codes

    在这个名为"C++ Codes"的压缩包中,可能包含了各种C++编程的示例代码、练习项目或库,涉及了C++的多个方面,例如基础语法、类与对象、模板、异常处理、STL(标准模板库)等。 **C++基础语法** C++的基础语法包括...

    Cracking Codes with Python (True PDF)

    Cracking Codes with Python: An Introduction to Building and Breaking Ciphers (True PDF)

    The.Theory.of.Error-Correcting.Codes

    - **克尔多克码(Kerdock Codes)**与**预备拉塔码(Preparata Codes)**:这两类码具有良好的非线性性质,适合于某些特定的应用场景。 - **自对偶码(Self-Dual Codes)**:这类码具有独特的数学性质,在编码理论中占有...

    MATLAB Codes for Finite Element Analysis_matlab_

    标题中的“MATLAB Codes for Finite Element Analysis”表明这是一个关于使用MATLAB进行有限元分析的资源。有限元分析(Finite Element Analysis, FEA)是一种数值计算方法,常用于工程领域,如结构力学、流体力学等...

    Low Density Parity Check Codes

    ### 低密度奇偶校验码 (Low Density Parity Check Codes) #### 概述 低密度奇偶校验码(Low Density Parity Check Codes,简称LDPC码)是一种高效的线性错误校正码,最初由罗伯特·G·加拉格尔(Robert G. ...

    Learning Binary Codes for Collaborative Filtering

    codes for collaborative filtering, which enables us to efficiently make recommendations with time complexity that is independent of the total number of items. We propose to construct binary codes for ...

    fk2_codes fk2_codes

    【描述】"fk fk2_codes 2_codes fk2_codes fk2_codes fk2_codes fk2_codes fk2_codes"看起来像是重复的关键词,"fk"可能是缩写,可能是开发者的名字、项目代号或者是某种编程概念的简写。"2_codes"可能表示第二版...

    turbo codes 的matlab仿真程序

    涡轮码(Turbo Codes)是一种纠错编码技术,它在通信和存储系统中扮演着重要的角色,因其接近香农极限的性能而闻名。MATLAB是一个强大的数学计算软件,广泛用于科学计算、工程仿真以及信号处理等领域。在这个"turbo ...

    Introduction To Error Correcting Codes

    错误校正码(Error-Correcting Codes, ECC)是信息理论中的一个基础概念,它们在数字通信和存储领域扮演着至关重要的角色。为了确保数据在传输或存储过程中遭受干扰时,接收方能够准确还原发送方的信息,错误校正码...

    Windows Message Codes(系统消息代码).pdf

    Windows Message Codes(系统消息代码)

    Variable-length Codes for Data Compression.pdf

    《Variable-length Codes for Data Compression》是一本关于数据压缩领域中变长编码技术的专业书籍。本书由David Salomon教授撰写,详细介绍了各种变长编码算法及其在实际数据压缩场景中的应用。 #### 什么是变长...

    Fundamentals of Error-Correcting Codes

    错误纠正编码(Error-Correcting Codes,ECC)是通信和数据存储领域中至关重要的技术,旨在检测并修复数据传输或存储过程中可能出现的错误。《Fundamentals of Error-Correcting Codes》这本书由W. Cary Huffman撰写...

    codes for Stanford ML course

    This rar-file contains all the codes of the Stanford ML courses, you can download it and execute them in you matlab paltform

    [2009] Channel Codes Classical and Modern

    《Channel Codes: Classical and Modern》这本书提供了全面而深入的信道编码理论和技术介绍,涵盖了传统到现代的各种编码方法。 #### 二、基本概念与原理 信道编码技术旨在提高数据传输的可靠性和效率。通过在原始...

Global site tag (gtag.js) - Google Analytics