AdvancedRating 1800
All Ways to Split a Sentence
Insert spaces into the text so that every piece is a dictionary word. Print every possible sentence in alphabetical order, or NONE.
Input
The text; then k; then k words.
Output
Lines.
Sample 1
Input
catsanddog 5 cat cats and sand dog
Output
cat sand dog cats and dog
Sample 2
Input
pineapplepenapple 5 apple pen applepen pine pineapple
Output
pine apple pen apple pine applepen apple pineapple pen apple
Output appears here