[Vijos 1379] expansion of the string

Source: Internet
Author: User
Tags lowercase

Describe
In the "Reading program writing results" question in the preliminary preliminaries group, we gave an example of a string expansion: if the input
String, containing strings similar to "d-h" or "4-8", we use it as a shorthand, output, with continuous
The increment of the Alpha string replaces the minus sign, which is the output of the above two substrings as "defgh" and "45678" respectively. In
In this subject, we make the string expansion more flexible by adding some parameter settings. The specific agreement is as follows:
1. The following situation is required to do the expansion of the string: in the input string, there is a minus "-", minus both sides of the same lowercase letters or the same number, and in the Order of ASCII code, the right character of the minus sign is strictly greater than the left character.
2. Parameter P1: expansion mode. P1=1, for the word mother and child string, filled with lowercase letters, p1=2, for the character string, filled with uppercase letters. In both cases, the number substring is populated in the same way. P1=3, whether it is a substring or a digital string, are populated with the same number of letters to fill the asterisk "*" to fill.
3. Parameter P2: The number of repetitions of the fill character. P2=k indicates that the same character is to be continuously populated with K. For example, when p2=3, the substring "d-h" should be extended to "Deeefffgggh". The characters on both sides of the minus sign do not change.
4. Parameter p3: Change to reverse: p3=1 means to maintain the original order, p3=2 means to use reverse output, note that this time still does not include the characters at both ends of the minus sign. For example, when P1=1, p2=2, p3=2, the substring "d-h" should be extended to "Dggffeeh".
5. If the character to the right of the minus sign is exactly the successor to the left character, delete only the middle minus sign, for example: "D-E" should be output as "de", "3-4" should be output as "34". If the character to the right of the minus sign is less than or equal to the left character in the order of ASCII, the middle minus sign is preserved, for example: "d-d" should be output as "d-d" and "3-1" should be output as "3-1".
Format

Input format
Includes two lines:
The 1th behavior is a 3 positive integer separated by a space, one time representing the parameter p1,p2,p3.
The 2nd behavior is a row of strings, consisting only of numbers, lowercase letters, and minus "-". There are no spaces at the beginning of the line or at the end.
Output format

Only one row, which is the expanded string.
Example 1:
Sample Input 1
1 2 1
Abcs-w1234-9s-4zz
Sample Output 1
Abcsttuuvvw1234556677889s-4zz
Limit
1s

Ideas
impersonation for string manipulation
The operation process is written as a function to output must pay attention to the details to consider special circumstances
like '-' Start, '-' together, and when p1=2, numbers can't be treated like lowercase letters .
The code is as follows

#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <
cmath> #include <cstring> #define N 1000005 using namespace std;
Char A[n];
int p1,p2,p3;
    void Deal (char X,char y) {if (x==y-1) return;//if not expanded, simply return because the X and y Char temp[500] have been output;
    int p=0;
            for (int i=x+1;i<=y-1;i++) {for (int j=1;j<=p2;j++) {if (p1==1) temp[++p]=i;
            else if (p1==2&&i>= ' a ' &&i<= ' z ')//p1=2 the letter case temp[++p]=i-' a ' + ' a ';
            else if (p1==2&&i>= ' 1 ' &&i<= ' 9 ') the number of//p1=2 is temp[++p]=i;
        else if (p1==3) temp[++p]= ' * ';
    }} if (p3==1)//Reverse output condition for (int i=1;i<=p;i++) cout<<temp[i];
else if (p3==2) for (int i=p;i>=1;i--) cout<<temp[i];
    } int main () {scanf ("%d%d%d", &AMP;P1,&AMP;P2,&AMP;P3);
    scanf ("%s", a+1); int Len=strlen (a+1);
            for (int i=1;i<=len;i++) {if (a[i]== '-') {char x=a[i-1];
            Char y=a[i+1]; if (x>= ' a ' &&x<= ' z ' &&y<= ' z ' &&y>= ' a ' &&x<y| |
                x>= ' 0 ' &&x<= ' 9 ' &&y>= ' 0 ' &&y<= ' 9 ' &&x<y) {//Meet condition not output '-' output two-character expansion
                Deal (x, y); 
            cout<< "" << "Deal" << "";
    } else cout<<a[i];//does not satisfy the output '-'} else cout<<a[i]; as S-4 }
}

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.