1140 Jam Counting Method 2006-year NOIP National League popularity Group

Source: Internet
Author: User

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.

Sample Input Sample Input

2 10 5

Bdfij

Sample Output Sample Output

Bdghi

Bdghj

Bdgij

Bdhij

Befgh

See example: {b,c,d,e,f,g,h,i,j}

The i,j cannot be moved backwards;

So only F moves forward, forming a new jam number

Topic Analysis:

{B,c,d,e,f,g,h,i,j};-àbdghi

I can also move backwards so

{B,C,D,E,F,G,H,I,J};-ÀBDGHJ

J can't move, so H moves backwards.

{B,c,d,e,f,g,h,i,j};-àbdgij

IJ can't move back, so move backwards.

{B,c,d,e,f,g,h,i,j};-àbdhij

Hij back to move, then find D to move backwards;

{B,C,D,E,F,G,H,I,J};-ÀBEFGH

The title only lets find five, so the output of five,

If not enough, there are several outputs. Actually, the numbers are more than five.

Above is just a basic idea

To see the code (not my own *^__^*)

#include <bits/stdc++.h>

using namespace Std;

int s,t,w,sum=0,k;

int main ()

{

string S1;

cin>>s>>t>>w>>s1;

while (SUM<5)

{

for (int i=w-1;i>=0;i--)//Loop

{

k=s1[i]-' a ' +w-i; Judging, looking forward from the back to this letter and the letters behind it

If there are other letters between them, you can move them back.

if (k<t)//If not 10

{

s1[i]=s1[i]+1; Move the letter that is smaller than the previous string to the first

for (int j=i+1;j<w;j++)//immediately followed by a letter plus a

s1[j]=s1[j-1]+1;

sum++;

cout<<s1<<endl;

break;//string found and jumped out for

}

}

}

return 0;

}

1140 Jam Counting Method 2006-year NOIP National League popularity Group

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.