[NOIP2007 Improvement Group] String Expansion

Description of topic

In the question of “reading program writing results” in the popularization group of the preliminary round, we gave an example of string expansion: if the input string contains a string similar to d-h or 4 -8 string, we regard it as a shorthand. When outputting, replace the minus sign with a continuously increasing letter or number string, that is, output the above two substrings as defgh and 45678. In this question, we make the string expansion more flexible by adding some parameter settings. The specific agreement is as follows:

(1) When encountering the following situation, you need to expand the string: in the input string, there is a minus sign -, and both sides of the minus sign are lowercase letters or numbers, and according to ASCII code sequence, the character to the right of the minus sign is strictly greater than the character to the left.

(2) Parameter p_1p1?: Expansion mode. When p_1=1p1?=1, for alphabetic substrings, fill with lowercase letters; when p_1=2p1?=2, for alphabetic substrings, fill with uppercase letters. The numeric substrings are padded the same way in both cases. When p_1=3p1?=3, whether it is a substring of letters or a string of numbers, it is filled with the same number of asterisks * as the number of letters to be filled.

(3) Parameter p_2p2?: The number of repetitions of filling characters. p_2=kp2?=k means that the same character should be filled kk consecutively. For example, when p_2=3p2?=3, the substring d-h should expand to deeeffffgggh. The characters on either side of the minus sign are unchanged.

(4) Parameter p_3p3?: Whether to change to reverse order: p_3=1p3?=1 means to maintain the original order, p_3=2p3?=2 means to output in reverse order, note that the characters at both ends of the minus sign are still not included at this time. For example, when p_1=1p1?=1, p_2=2p2?=2, p_3=2p3?=2, the substring d-h should be expanded to dggffeeh.

(5) If the character on the right of the minus sign happens to be the successor of the character on the left, only delete the minus sign in the middle, for example: d-e should be output as de, 3- 4 should be output as 34. If the character on the right of the minus sign is less than or equal to the character on the left according to the order of the ASCII code, the minus sign in the middle should be kept when outputting, for example: d-d should be output as d-d, 3-1 should output as 3-1.

Input format

There are two lines.

The 11th line is 33 positive integers separated by spaces, representing the parameters p_1,p_2,p_3p1?,p2?,p3? in turn.

Line 22 is a string consisting only of numbers, lowercase letters and minus signs -. There are no spaces at the beginning or end of the line.

Output format

A total of one line, for the expanded string.

Sample input and output

Enter #1 to copy

1 2 1
abcs-w1234-9s-4zz

Output #1 Copy

abcsttuuvvw1234556677889s-4zz

Enter #2 to copy

2 3 2
a-d-d

Output #2 Copy

aCCCBBBd-d

Instructions/Tips

40\@% of the data satisfies: the length of the string does not exceed 55.

100\ 0% of the data satisfy: 1 \le p_1 \le 3,1 \le p_2 \le 8,1 \le p_3 \le 21≤p1?≤3,1≤p2?≤8,1≤p3?≤ 2. String length does not exceed 100100.

NOIP 2007 Improve the second question

A mock question that can be done correctly with a little care.

Let’s analyze the pitfalls and layering ideas:

Pit point:

1. “-” may appear in the first or last one, and may appear continuously at the same time, use judgment for special treatment

2. If x is a number and y is a letter in x-y, you should choose not to expand! (does not overlap with the special cases mentioned in the title)

layered:

1. Is it a symbol or “-“, and at the same time add special treatment for “-“

2. The relationship between x and y, divided into <=, >, x + 1=y

3. Is x and y a letter or a number at the same time?

4. Cycle through layers of p1, p3, and p2

attach code

#include <bits/stdc++.h>
using namespace std;
int p1,p2,p3;
vector<char> ans;
string s;
int main()
{
    cin >> p1 >> p2 >> p3 >> s;
    for(int i=0;i<s. size();i ++ )
    {
        if(s[i]!='-') ans. push_back(s[i]);
        else if((i==0 || i==s.size()-1) & amp; & amp; s[i]=='-' ) ans.push_back('-');
        else if(s[i]=='-' & amp; & amp; (s[i-1]=='-' || s[i + 1]=='-')) ans.push_back(' -');
        else if(s[i]=='-')
        {
            if(s[i-1]>=s[i + 1] || (s[i-1]<58 & amp; & amp; s[i + 1]>96)) ans.push_back('-' );
            else if(s[i + 1]==s[i-1] + 1) continue;
            else
            {
                if(p1==3)
                {
                    for(int k=1;k<=(s[i + 1]-s[i-1]-1)*p2;k + + ) ans.push_back('*');
                }
                else if(s[i + 1]<=57 & amp; & amp; s[i + 1]>=48 & amp; & amp; s[i-1]<=57 & amp; & amp; s[ i-1]>=48)
                {
                    if(p3==1)
                    {
                        for(int k=s[i-1] + 1; k<=s[i + 1]-1; k + + )
                            for(int j=1;j<=p2;j++)
                                ans.push_back(char(k));
                    }
                    else if(p3==2)
                    {
                        for(int k=s[i+1]-1;k>=s[i-1]+1;k--)
                            for(int j=1;j<=p2;j++)
                                ans.push_back(char(k));
                    }
                }
                else if(s[i + 1]<=122 & amp; & amp; s[i + 1]>=97 & amp; & amp; s[i-1]<=122 & amp; & amp; s[ i-1]>=97)
                {
                    if(p1==1)
                    {
                        if(p3==1)
                        {
                            for(int k=s[i-1] + 1; k<=s[i + 1]-1; k + + )
                                for(int j=1;j<=p2;j++)
                                    ans.push_back(char(k));
                        }
                        else if(p3==2)
                        {
                            for(int k=s[i+1]-1;k>=s[i-1]+1;k--)
                                for(int j=1;j<=p2;j++)
                                    ans.push_back(char(k));
                        }
                    }
                    else if(p1==2)
                    {
                        if(p3==1)
                        {
                            for(int k=s[i-1] + 1; k<=s[i + 1]-1; k + + )
                                for(int j=1;j<=p2;j++)
                                    ans.push_back(char(k-32));
                        }
                        else if(p3==2)
                        {
                            for(int k=s[i+1]-1;k>=s[i-1]+1;k--)
                                for(int j=1;j<=p2;j++)
                                    ans.push_back(char(k-32));
                        }
                    }
                }
            }
        }
    }
    for(int i=0;i<ans. size();i + + ) cout << ans[i];
    return 0;
}