A report on the expansion of the 1098 string in Luo gu

Source: Internet
Author: User

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
  1. program expand;
  2. Var
  3. P1,p2,p3,l,i,j,k:longint;
  4. S:string;
  5. A:array[1..100] of longint;
  6. Begin
  7. READLN (P1,P2,P3);
  8. READLN (s);
  9. L:=length (s);
  10. For i:=1 to l do
  11. A[i]:=ord (S[i]);
  12. Write (s[1]);
  13. For i:=2 to l1 do
  14. if a[i]=
  15. begin
  16. if (a[i-1]=a[i]) or (a[i]=a[i+1]) Then
  17. begin
  18. write (s[i]);
  19. Continue
  20. end;
  21. if a[i-1]+1=a[i+1] then continue;
  22. if (a[i-1]+1<a[i+1]) and ((96<a[i-1]) or (a[i+1]<) Then
  23. begin
  24. if (p1=1) and (a[i-1]>) Then
  25. begin
  26. if p3=1 Then
  27. For j:=a[i-1]+1 to a[i+1]-1 do
  28. For k:=1 to p2 do
  29. Write (Chr (j));
  30. if p3=2 Then
  31. For j:=a[i+1]-1 downto a[i-1]+1 do
  32. For k:=1 to p2 do
  33. Write (Chr (j));
  34. end;
  35. if (p1=2) and (a[i-1]>) Then
  36. begin
  37. if p3=1 Then
  38. For j:=a[i-1]+1 to a[i+1]-1 do
  39. For k:=1 to p2 do
  40. Write (Chr (J32));
  41. if p3=2 Then
  42. For j:=a[i+1]-1 downto a[i-1]+1 do
  43. For k:=1 to p2 do
  44. Write (Chr (J32));
  45. end;
  46. if ((p1=1) or (p1=2) and (a[i-1]<) Then
  47. begin
  48. if p3=1 Then
  49. For j:=a[i-1]+1 to a[i+1]-1 do
  50. For k:=1 to p2 do
  51. Write (Chr (j));
  52. if p3=2 Then
  53. For j:=a[i+1]-1 downto a[i-1]+1 do
  54. For k:=1 to p2 do
  55. Write (Chr (j));
  56. end;
  57. if p1=3 Then
  58. For j:=a[i+1]-1 downto a[i-1]+1 do
  59. For k:=1 to p2 do
  60. Write (' * ');
  61. End
  62. Else write (s[i]);
  63. End
  64. Else write (s[i]);
  65. write (s[l]);
  66. End.

(This article is the author original, without permission not reproduced)

A report on the expansion of the 1098 string in Luo gu

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.