Luo gu 1098 the expansion of the string
Address: http://www.luogu.org/problem/show?pid=1098
Title Description
In the "Reading program writing results" question in the preliminaries group, we gave an example of a string expansion: if, in the input string, it contains strings similar to "d-h" or "4-8", we use it as a shorthand for the output, using successive increments of letters to receive a number string instead of the minus sign, i.e., The above two substrings are output as "defgh" and "45678" respectively. 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: whether 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 the end 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 on the right side 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".
Input/output format
Input format:
The input file expand.in 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:
The output file expand.out only one row, which is the expanded string.
Input/Output sample
Input Sample # #:
"Input Example 1" 1 2 1abcs-w1234-9s-4zz "Input Sample 2" 2 3 2a-d-d
Sample # # of output:
"Output Example 1" abcsttuuvvw1234556677889s-4zz "Output Sample 2" acccbbbd-d
Description
40% of data: string length not exceeding 5
100% of the data meet: 1<=p1<=3,1<=p2<=8,1<=p3<=2. String length not exceeding 100
NOIP 2007 Raising the second question
Exercises
Analog + string
It is also a pure simulation problem. The problem is more cumbersome, special circumstances and details I will not say more (see Code). It is worth mentioning that the author uses the Ord and CHR functions associated with the ASCII code in the string manipulation, which is very effective in the problem of string manipulation. The following code is attached.
Code
- program expand;
- Var
- P1,p2,p3,l,i,j,k:longint;
- S:string;
- A:array[1..100] of longint;
- Begin
- READLN (P1,P2,P3);
- READLN (s);
- L:=length (s);
- For i:=1 to l do
- A[i]:=ord (S[i]);
- Write (s[1]);
- For i:=2 to l1 do
- if a[i]=
- begin
- if (a[i-1]=a[i]) or (a[i]=a[i+1]) Then
- begin
- write (s[i]);
- Continue
- end;
- if a[i-1]+1=a[i+1] then continue;
- if (a[i-1]+1<a[i+1]) and ((96<a[i-1]) or (a[i+1]<) Then
- begin
- if (p1=1) and (a[i-1]>) Then
- begin
- if p3=1 Then
- For j:=a[i-1]+1 to a[i+1]-1 do
- For k:=1 to p2 do
- Write (Chr (j));
- if p3=2 Then
- For j:=a[i+1]-1 downto a[i-1]+1 do
- For k:=1 to p2 do
- Write (Chr (j));
- end;
- if (p1=2) and (a[i-1]>) Then
- begin
- if p3=1 Then
- For j:=a[i-1]+1 to a[i+1]-1 do
- For k:=1 to p2 do
- Write (Chr (J32));
- if p3=2 Then
- For j:=a[i+1]-1 downto a[i-1]+1 do
- For k:=1 to p2 do
- Write (Chr (J32));
- end;
- if ((p1=1) or (p1=2) and (a[i-1]<) Then
- begin
- if p3=1 Then
- For j:=a[i-1]+1 to a[i+1]-1 do
- For k:=1 to p2 do
- Write (Chr (j));
- if p3=2 Then
- For j:=a[i+1]-1 downto a[i-1]+1 do
- For k:=1 to p2 do
- Write (Chr (j));
- end;
- if p1=3 Then
- For j:=a[i+1]-1 downto a[i-1]+1 do
- For k:=1 to p2 do
- Write (' * ');
- End
- Else write (s[i]);
- End
- Else write (s[i]);
- write (s[l]);
- End.
(This article is the author original, without permission not reproduced)
A report on the expansion of the 1098 string in Luo gu