Question: 1 * * * * Expand String In this part, we define a special pattern that can be used in strings to expand the original
Expand String
In this part, we define a special pattern that can be used in strings to
"expand" the original string. The format of this pattern is defined as
No part
where is a onedigit number and the "part" inside of the
parentheses is the substring you want to repeat. By expanding a string
including this patterns you basically need to repeat the "part" for of
times in that string.
For exanple,
Original string: Hn
Expanded string: "Hannannann"
Original String: "I really want to eat candy."
Expanded String: "I really really really want to eat candy."
Original string: ABC
Expanded string: ABCC"
ASSUNPTIONS:
To simplify the inplenentation, you can assune:
The original string will ONLY include ONE of such pattern.
The can only be a ONEdigit positive number, ie
The three characters and are special characters. They won'T
be used as the regular contentdata of a string. So whenever there is a
you can assune there will be such a pattern around.
There is NO NESTED repeat patterns, ie a pattern inside of another
pattern.
pts
a
expandstrlen
STEP : Estinate how much space is needed for the expanded string.
To allocate space on the heap, you have to first scan and parse the
original string and calculate the size for the new string PRECISELY.
Let's write a dedicate function expandstrlen to do this.
HINT:
Whenver finding a use the character on the left as the N Convert
this character to an int for later use.
Then find the charaters after a and between and as the "part"
in the pattern. Calculate the length of this part and nultiply it by the number
then you have the size of the expanded part
in the new string.
To calculate the entire space required by the new string. A better way is
to calculate the change or difference between the new and original string.
When calculating this size change in the new string, you have to consider the
byte for the and bytes for
Given an input string, this function will parse the string and calculate the
size required for the new string.
You CAN NOT use any function fron string.h EXCEPT for strlen;
Eparan input the original string
ereturn neary space required by the new string.
int expandstrlenchar input
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
