You are given a template string T on a single line, which may contain zero or more placeholders of the exact form {{name}}, where name is one or more characters from lowercase letters, digits, and underscores. You are also given n definition lines, each of the exact form key=value (the value may contain any characters except a newline, including = itself — always split a definition line on only its FIRST =).
Replace every well-formed placeholder {{name}} in T with the value defined for that name. If name has no definition, leave that placeholder exactly as-is (including its braces) in the output. If the same key is defined more than once, the LAST definition for that key wins. A {{ that is not followed later by a matching name and }} forming a well-formed placeholder (for example {{}} with an empty name, or a stray unmatched {{) is left completely untouched as ordinary text. Substituted values are inserted literally — they are never themselves re-scanned for placeholders.
Line 1: the template T (may be empty).
Line 2: an integer n.
Lines 3..n+2: each a definition key=value.
T with all well-formed, defined placeholders substituted, on one line.
T ≤ 300key consists of lowercase letters, digits, and underscores, 1 to 30 charactersExample 1
Input
Hello, {{name}}!
1
name=WorldExpected
Hello, World!
Explanation
The single placeholder {{name}} is replaced with its defined value, giving `Hello, World!`.
Example 2
Input
{{a}}-{{b}}
1
a=1Expected
1-{{b}}Explanation
{{a}} is defined and replaced with 1; {{b}} has no definition so it is left as `{{b}}`, giving `1-{{b}}`.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →