UVaOJ146---ID Codes

本文介绍了一个用于生成公民身份识别代码的程序。该程序接受一个不超过50个字符的字符串作为输入,并输出其后续的字母组合,如果当前输入已经是特定字符集合下的最后一个组合,则输出‘NoSuccessor’。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

146 - ID Codes

Time limit: 3.000 seconds

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
#include<cstdio>
#include<cstring>
#include<cstdlib>

char s[60];

int cmp( const void *_p, const void *_q)
{
    char *p, *q;
    p = (char *)_p;
    q = (char *)_q;
    return *p - *q;
}

int main()
{
    int k;
    while( true)
    {
        scanf( "%s", s);
        if( s[0] == '#') break;
        int len = strlen( s);
        for( k = len - 1; k > 0; k --)
            if( s[ k] > s[ k - 1])
                break;
        if( k == 0)
        {
            printf( "No Successor\n");
            continue;
        }
        for( int i = len - 1; i >= k; i --)
        if( s[i] > s[k - 1])
        {
            char temp = s[i];
            s[i] = s[k - 1];
            s[k - 1] = temp;
            break;
        }
        qsort( s + k, len - k, sizeof( char), cmp);
        printf( "%s\n", s);
    }
    return 0;
}


Happy Captcha简易验证码是一款易于使用的Java验证码软件包,旨在花最短的时间,最少的代码量,实现Web站点的验证码功能。 Happy Captcha简易验证码提供了图片和动画两种展现形式,验证码内容包括中文(收录3500个常用汉字),阿拉伯数字(09),中文数字(零至九),中文大写数字(零至玖),数字与字母混合(09-az-AZ),数字与小写字母混合(09-az),数字与大写字母混合(09-AZ),纯小写字母,纯大写字母,大小写字母混合以及运算表达式(阿拉伯数字运算表达式和中文运算表达式)等12种类型。 Happy Captcha简易验证码完全遵循Apache 2.0开源许可协议,你可以自由使用该软件,如您在使用Happy Captcha时发现软件的任何缺陷,欢迎随时与作者联系。 Happy Captcha简易验证码安装: 如果你的项目使用的是Maven进行依赖管理,你只需向pom.xml文件添加下面的配置即可:     com.ramostear   Happy-Captcha   1.0.1   Gradle用户则可以通过引入如下的配置获取Happy Captcha: implementation 'com.ramostear:Happy-Captcha:1.0.1' Happy Captcha简易验证码使用: HappyCaptcha在设计时力求过程的简洁,在默认情况下,你只需要书写一行代码即可生成漂亮的验证码图片。下面是HappyCaptcha的使用示例: @Controller public class HappyCaptchaController{     @GetMapping("/captcha")     public void happyCaptcha(HttpServletRequest request,HttpServletResponse response){         HappyCaptcha.require(request,response).build().finish();     } } 对于HappyCaptcha而言,只有request和response是必须提供的参数,其余参数都可以使用缺省值。 在默认情况下,HappyCaptcha生成的验证码以图片形式展现,内容为09-az-A~Z的字符随机组合,字符长度为5,图片宽度为160,高度为50,字体为微软雅黑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值