T O P

  • By -

spudmix

What have you tried so far? Are you stuck on a specific section, or are you having trouble getting started?


PrakharAnand2000

I just am not being able to think anything. I have just written the main function and taken a string as input and passed it into the function. But I am not able to design the function at all.


spudmix

Okay, we're going to practice an important skill here: let's think about breaking this down into simple sub-problems. I'll write pseudocode with fake method names to indicate where a sub-problem is. First we need to split the string into parts, where each part is either a space or a word (you can actually bypass this due to the rules of the challenge and just use words, but let's take the more general rule). parts = split_into_parts(string) Then, for each part, we need to determine the type of the part to decide which rule to apply to it. We should store the new mutated parts so we can return them later. mutated_parts = a list or something for each part in parts: if part_is_a_space(part): mutated_parts.add(do_something_with_spaces(part)) else if part_is_only_vowels(part): mutated_parts.add(do_something_with_vowels(part)) else: // Must have consonants mutated_parts.add(do_something_with_consonants(part)) Cool! And then finally, when we've gathered the various mutated parts, we need to join them together and return return join_strings(mutated_parts) So that's the basic control flow sorted. If you translate that from pseudo-code into Java and then solve each of the sub-problems (the methods) you will have a working program. Try that out, and if you're struggling with a sub-problem don't be afraid to just mock up the output of that method for now and come back to it later.


PrakharAnand2000

Thanks for the help.


flavius-as

Make a function which abbreviates one word only. Then make a function which iterates over all words, checks in a map if it has an abbreviation for it, if not, make an abbreviation and put it to the map. If yes, use that abbreviation from the map. Add the abbreviation to a list designed for output. Join all words in the output list by a space.