11
(No, not this nor any of these)
Given a string and a list of strings, fill in the all blanks in the input string with corresponding strings.
Input/Output
The input string contains only alphabetic characters, spaces, and underscores. It is nonempty and does not start with an underscore. In other words, the input string matches the regex ^[a-z A-Z]([a-z A-Z_]*[a-z A-Z])?$
Every string in the input list is nonempty and contains only alphanumeric characters and spaces. In other words, they match the regex ^[a-z A-Z]+$
.
A blank is a contiguous sequence of underscores (_
) which is neither preceded nor proceeded by an underscore.
The input string contains n
blanks for some positive integer n
, and the list of strings contains exactly n
strings.
The output is obtained by replacing each k
-th blank in the input string by the k
-th string in the input list of strings.
Example
Given an input string "I like _____ because _______ _____ing"
and a list of strings ["ice cream", "it is", "satisfy"]
, we can find the output as follows:
- The first blank comes directly after
"like "
. We fill that in with"ice cream"
to get"I like ice cream because ______ _____ing"
. - The second blank comes directly after
"because "
. We fill that in with"it is"
to get"I like ice cream because it is _____ing"
. - The third blank comes directly after
"is "
. We fill that in with"satisfy"
to get"I like ice cream because it is satisfying"
.
We output the final string "I like ice cream because it is satisfying"
.
Test Cases
input string, input list => output
"Things _____ for those who ____ of how things work out _ Wooden",["work out best","make the best","John"] => "Things work out best for those who make the best of how things work out John Wooden"
"I like _____ because _______ _____ing",["ice cream","it is","satisfy"] => "I like ice cream because it is satisfying"
"If you are ___ willing to risk _____ you will ha_o settle for the ordi_____Jim ______n",["not","the usual","ve t","nary ","Roh"] => "If you are not willing to risk the usual you will have to settle for the ordinary Jim Rohn"
"S____ is walking from ____ to ____ with n_oss of ___ W_____ Churchill",["uccess","failure","failure","o l","enthusiasm","inston"] => "Success is walking from failure to failure with no loss of enthusiasm Winston Churchill"
"If_everyone_is_thinking ____ ____ somebody_isnt_thinking G____e P____n",[" "," "," ","alike","then"," "," ","eorg","atto"] => "If everyone is thinking alike then somebody isnt thinking George Patton"
"Pe_________e __say ____motivation does__ last Well___her doe_ bathing____thats why we rec____nd it daily _ __________lar",["opl","often ","that ","nt"," neit","s"," ","omme","Zig","Zig"] => "People often say that motivation doesnt last Well neither does bathing thats why we recommend it daily Zig Ziglar"
5A lot of explanations for trivial task. – None – 2017-09-21T03:07:33.160