35: string expansion, 35: string expansion

Source: Internet
Author: User

35: string expansion, 35: string expansion
35: string expansion

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

In the "reading program writing results" issue of the popularity group in the preliminary round, we gave an example of string expansion: If in the input string, it contains a string similar to "d-h" or "4-8", and we use it as a short name. when outputting, we use a progressively increasing letter to get a number string to replace the minus sign, that is, the two substrings are output as "defgh" and "45678" respectively ". In this question, we add some parameter settings to make the expansion of strings more flexible. The specific conventions are as follows:

(1) In the following situations, expand the string: In the input string, the minus sign "-" appears, and both sides of the minus sign are lowercase letters or numbers, in the ASCII order, the characters on the right of the minus sign must be greater than those on the left.

(2) parameter p1: expansion mode. When p1 = 1, lowercase letters are entered for letters and substrings; When p1 = 2, uppercase letters are entered for letters and substrings. In both cases, the number substrings are filled in the same way. When p1 = 3, whether it is a letter or a number string, it is filled with an asterisk (*) with the same number of letters to be filled.

(3) parameter p2: number of repeated characters filled in. P2 = k indicates that the same character must be continuously filled with k characters. For example, when p2 is 3, the substring "d-h" should be extended to "deeefffgggh ". The characters on both sides of the minus sign remain unchanged.

(4) Whether to change the p3 parameter to backward order: p3 = 1 indicates that the original order is maintained, and p3 = 2 indicates that the output is in reverse order. Note that the characters at both ends of the minus sign are not included at this time. For example, when p1 = 1, p2 = 2, and p3 = 2, the substring "d-h" should be extended to "dggffeeh ".

(5) If the character on the right of the minus sign is the successor of the character on the left, only the minus sign in the middle is deleted. For example, "d-e" should be output as "de ", "3-4" should be output as "34 ". If the characters on the right of the minus sign are less than or equal to the characters on the left in the ASCII code order, the minus signs in the middle should be retained during output. For example: "d-d" should be output as "d-d", and "3-1" should be output as "3-1 ".

Input
There are two rows:
1st act three positive integers separated by spaces. Each positive integer represents the p1, p2, and p3 parameters.
2nd act as a string consisting of digits, lowercase letters, and minus. There is no space at the beginning or end of the line.

40% of the data meets the requirements: the string length cannot exceed 5;
100% of the data meets the following requirements: 1 <= p1 <= 3, 1 <= p2 <= 8, 1 <= p3 <= 2. The length of a string cannot exceed 100.
Output
There is only one row, which is the expanded string.
Sample Input
Example #2 1abcs-w1234-9s-4zz example #3 2a-d-d example #4 2di-jkstra2-6
Sample output
Sample #1: abcsttuuvvw1234556677889s-4zz sample #2: aCCCBBBd-d sample #3: constraint stra2 ************ 6
Source
Question 2 of NOIP2007 semi-finals Promotion Group
1 # include <iostream> 2 # include <cstring> 3 # include <cstdio> 4 # include <cmath> 5 using namespace std; 6 int z = 0; 7 char a [100001]; 8 int main () 9 {10 int p1, p2, p3; 11 cin> p1> p2> p3; 12 scanf ("% s", & a); 13 int n = strlen (a); 14 for (int I = 0; I <n; I ++) 15 {16 if (a [I] = '-' & a [I-1] <a [I + 1] & (a [I-1]> = 65 & & a [I-1] <= 90) & (a [I + 1]> = 65 & a [I + 1] <= 90 )) | (a [I-1]> = 90 & a [I-1] <= 122) & (a [I + 1]> = 90 & a [I + 1] <= 122 )) | (a [I-1]> = 48 & a [I-1] <= 57) & (a [I + 1]> = 48 & a [I + 1] <= 57 )))) // find the abbreviated string 17 {18 int l = a [I-1]; // ascll code table 19 int r = a [I + 1] on the left; // ascll code table 20 on the right side if (p3 = 1) 21 {22 for (int j = l; j <= r; j ++) 23 {24 for (int k = 1; k <= p2; k ++) 25 {26 if (j = l | j = r) 27 {28 break; 29 // cout <(char) j; // boundary value 30 // break; 31} 32 else 33 {34 if (p1 = 3) 35 {36 cout <"*"; 37} 38 else if (p1 = 1) // lowercase letter 39 {40 if (j> = 65 & j <= 90) 41 {42 a [j] = a [j] + 32; 43 cout <char (j + 32); 44 continue; 45} 46 else cout <char (j); 47 48} 49 else if (p1 = 2) 50 {51 if (j> = 90 & j <= 122) 52 {53 a [j] = a [j]-32; 54 cout <char (j-32 ); 55} 56 else cout <char (j); 57} 58} 59} 60 61} 62} // output 63 else if (p3 = 2) in sequence) 64 {65 for (int j = r; j> = l; j --) 66 {67 for (int k = 1; k <= p2; k ++) 68 {69 if (j = l | j = r) 70 {71 break; 72 // cout <(char) j; // boundary value 73 // break; 74} 75 else 76 {77 if (p1 = 3) 78 {79 cout <"*"; 80} 81 else if (p1 = 1) // lowercase letter 82 {83 if (j> = 65 & j <= 90) 84 {85 a [j] = a [j] + 32; 86 cout <char (j + 32); 87 continue; 88} 89 else cout <char (j); 90 91} 92 else if (p1 = 2) 93 {94 if (j> = 90 & j <= 122) 95 {96 a [j] = a [j]-32; 97 cout <char (j-32); 98} 99 else cout <char (j ); 100} 101} 102} 103 104} 105} // output 106 107} 108 else109 {110 cout in reverse order <a [I]; 111} 112 return 0; 113}

 

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.