Question: For a String s , we can refer the first third of a s as its head, the last third of it as its tail
For a String s we can refer the first third of a s as its head, the last third of it as its tail and the remaining characters as its middle.
If l is the length of a String, then let t ceilingl represent the length of the head and tail. The ceiling of a noninteger value x is the smallest integer c such that c x ceiling is ceiling is
For the String "marathon", the head is "mar", the middle is at and the tail is "hon".
One can chop a string by removing its head, middle or tail. Chopping off the head of "marathon" gives us the String "athon". Chopping off the tail of "marathon" gives us the String "marat", and chopping the middle gives us "marhon".
We will use h or H to denote chopping off the head of a string, t or T for chopping off the tail, and m or M for chopping off the middle.
We can dice "marathon" to the single character t using the chop sequence THHH which represents the following sequence of chops: "marathon" "marat" "rat" att
The end goal of this activity is to develop a program that determines, for each letter of the alphabet, the chopping sequence that allows us to obtain that letter from a given string.
Examples
Input: x; Output: NONONONONONONONONONONONONONONONONONONONONONONONONO We do not need to chop the string to obtain x
Input: "qwertyuiopasdfghjkl"; Output: HTHMTTNONOHHTMTHMTMHTTHHTHMTHHHMTTHHHMTHHTTMTTHHHHMTHHHHHTHHHHHHNONOHTTMTHHTTHMTMTMTTTMTHTTTHHTMTTMTHTTHMHMTTHNOMTMTTHNOMHMTTTNO
Input: "aaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaa"; Output: HHHHHHHHMHTTTTNONONONONONONONONONONONONONONONONONONONONONONONO
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
