The counting method of 2006Jam

Source: Internet
Author: User

Title Description Description

Jam is a science geek who likes to be unconventional. He does not use Arabic numerals, but uses lowercase English letters to count, and he feels that doing so will make the world more colorful. In his notation, the digits of each digit are the same (using the same number of letters), the letters are in the original order, the letters in front of them are smaller than the letters that follow them. We call this "number" jam numbers. In jam numbers, each letter differs from left to right and is strictly incremented. Each time, jam also specifies the range of letters used, for example, from 2 to 10, which means that only {B,C,D,E,F,G,H,I,J} letters can be used. If the number of digits is 5, then the number immediately after the jam number "Bdfij" should be "Bdghi". (If we use U, V to indicate jam number "Bdfij" and "Bdghi", then u<v< Span>, and there is no jam number P, so u<p<v< span>). Your task is: For a jam number read from the file, sequentially output the 5 jam numbers immediately following, if there are not so many jam numbers, then a few will output a few.

Enter a description Input Description

There are 2 lines, the 1th Act 3 positive integers, separated by a space:

S T W

(where S is the ordinal of the smallest letter used, T is the ordinal of the largest letter used.) W is the number of digits, these 3 numbers meet:1≤s<t< span>≤26, 2≤w≤t-s)

The 2nd behavior has a W lowercase string, which is a required jam number.

The data given is correct and does not have to be verified.

Output description Output Description

A maximum of 5 rows, the 5 jam numbers immediately following the input jam number, if there are not so many jam numbers, then a few will output a few. Output only one jam number per line, which is a string of W lowercase letters, no extra spaces

Sample input Sample Input

2 10 5

Bdfij

Sample output Sample Output

Bdghi

Bdghj

Bdgij

Bdhij

Befgh

Data range and Tips Data Size & Hint

Exercises

Simulation.

Each time the string to find the next, the method is as follows: from the back to determine whether this can add 1, the requirements are as follows: 1, he added 1 after the right interval; 2. He added one less than his next. Use K to indicate the last point that you can add 1 (if k=0 means that the number is the largest and exit), then let the number +1 and keep the subsequent number as small as possible (but to satisfy the condition).

var x,y,l,i,j,k:longint;

s:ansistring;

Begin

READLN (x,y,l);

READLN (s);

s:=s+ ' {';

For I:=1 to 5 do

Begin

For j:=l Downto 1 do

if (S[J]<>CHR (y+96)) and (SUCC (S[j]) <s[j+1]) then

Begin

K:=j;

Break

End

If K=0 then exit;

S[K]:=SUCC (S[k]);

For j:=k+1 to L do S[J]:=SUCC (S[j-1]);

Writeln (copy (s,1,l));

End

End.

The counting method of 2006Jam

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.