Question: Consider the Challenge Activity 7.3.2 (Replace abbreviation). We generalize the problem to the function decoded user tweet, acronym, full word) that returns the string obtained
Consider the Challenge Activity 7.3.2 (Replace abbreviation). We generalize the problem to the function decoded user tweet, acronym, full word) that returns the string obtained by replacing every occurrence of acronym in user tweet by full word. For the example given in the example, the de- coded tweet is obtained by a call to decoded 'Gotta go I will TTYL.' TTYL'talk to you later) For the general problem, one attempt is to repeatedly expand user.tweet by replacing each occurrence of acronym by full word. But there is a danger to this approach. Consider decoded ('abcdd' cd'bAfter replacing the first occurrence of 'cd' the user tweet bems 'abbcd' which again has another occurrence of 'cd' Replacing one more time, we end up with the string 'abbbc But, the resg string obtained is not the intended answer. It makes more sense if we just replace the single occurrence of cd' in 'abcdd' by bc' to give 'abbed', and returns that as the answer without further replacement. On the other hand, decoded ('abcdcd', cd, , 'bc') should return 'abbcbc ater two rounds of replacement Implement the function decoded according to the logic explained. Also, pro- vide a main program to test the correctness of decoded
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
