There is a sentence with many cats:
there is a cat house where many cats live. in the cat house, there is a cat called alice and a cat called bob. in this house where all cats live, a cat can be concatenated into a string of cats. The cat called alice likes to purr and the cat called bob likes to drink milk.
The Task
Concatenate (_
) all pairs of neighbouring words in the sentence and place each in between the any such pair if that pair occurs more than once in the sentence. Note that overlapping counts, so blah blah
occurs twice in blah blah blah
.
For example, if the cat
occurs more then once, add the concatenated words in between them like this: the the_cat cat
Example Output
there there_is is is_a a a_cat cat cat_house house where many cats live. in the the_cat cat cat_house house,
there there_is is is_a a a_cat cat cat_called called called_alice alice and a a_cat cat cat_called called called_bob bob.
the the_cat cat cat_called called called_alice alice likes likes_to to purr and the the_cat cat cat_called called called_bob bob likes likes_to to drink milk.
Some more examples:
milk milk milk milk milk_milk milk milk_milk milk
a bun and a bunny a bun and a bunny
milk milk milk. milk milk milk.
bun bun bun bun. bun bun_bun bun bun_bun bun bun.
Notes
- All
utf-8
characters are allowed. Meaning that punctuations are part of the input. - Punctuation becomes part of the word (e.g., with
in the house, is a cat
the wordhouse,
includes the comma)
house house_where where
, sincehouse where
appears twice? (Actually, I think the example output does not match the example input.) \$\endgroup\$milk milk
occur twice or once inmilk milk milk
? (I'd guess twice so "yes" but I don't know) \$\endgroup\$