[The topic of the popularity group is very watery] Jam notation

Source: Internet
Author: User

[Description]

Jam is a strange scientist. Instead of counting Arabic numerals, he uses lowercase English letters to count. He thinks this will make the world more colorful. In his counting method, each number has the same number of digits (using the same number of letters). English letters are in the original order, and the first letter is smaller than the next letter. We call this "Number" a jam number. In jam numbers, each letter is different from each other, and the numbers are strictly incrementing from left to right. Each time, jam also specifies a letter range, for example, from 2 to 10, indicating that only {B, C, D, E, F, G, H, I, j. If the number is 5, the number that follows the jam number "bdfij" should be "bdghi ". (If we use U and V to represent the numbers "bdfij" and "bdghi" in turn, u <v, and there is no jam number P, so that u <p <v ). Your task is: For a jam number read from a file, output the five jam numbers followed by the following in order. If there are not so many jam numbers behind, then there are several outputs.

[Input format]

There are two rows in the input file, with 1st rows and three positive integers separated by a space:
S t w
(S indicates the serial number of the smallest letter used, and t indicates the serial number of the largest letter used. W is the number of digits, and the three numbers meet the following requirements: 1 ≤ S <T ≤ 26, 2 ≤ W ≤ t-s)
The 2nd behavior is a string with W lower-case letters and is a qualified jam number.
The data is correct and does not need to be verified.

[Output format]

The output file can contain a maximum of five lines, which are the five jam numbers that follow the input jam number. If there are not so many jam numbers following the output file, a few will be output. Each line outputs only one jam number, which is a string consisting of W lower-case letters and does not contain any extra space.

[Example input]

2 10 5

Bdfij

[Sample output]

Bdghi
Bdghj
Bdgij
Bdhij
Befgh

[Analysis]

Use the permutation method to solve the problem.

 

# Include <stdio. h> # include <string. h> # define maxn 100int num, S, T, W; int A [maxn], B [maxn]; bool V [maxn]; bool start, exit; char ss [maxn]; void make (int x) {If (exit) return; If (x> W) {If (start) {++ num; if (Num> 5) {exit = 1; return;} For (INT I = 1; I <= W; ++ I) printf ("% C ", A [I] + 'a'-1); printf ("\ n");} else {int same = 1; for (INT I = 1; I <= W; ++ I) if (a [I]! = B [I]) {same = 0; break;} If (Same) Start = 1 ;}} else {for (INT I = A [X-1] + 1; I <= T; ++ I) if (! V [I]) {v [I] = 1; A [x] = I; make (x + 1); V [I] = 0 ;}}} int main () {scanf ("% d % s", & S, & T, & W, SS); For (INT I = 0; I <W; ++ I) B [I + 1] = ss [I]-'A' + 1; A [0] = s-1; make (1 ); return 0 ;}

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.