#K96327. Customized Message Generator

    ID: 39062 Type: Default 1000ms 256MiB

Customized Message Generator

Customized Message Generator

In this problem, you are given a set of message templates and a list of user input strings. Each template contains placeholders enclosed in curly braces (e.g., {name}). Each user input string begins with a template index followed by key-value pairs (with the format key=value). Your task is to generate customized messages by replacing the placeholders in the selected template with the corresponding values provided in the user input.

The replacement is done by a simple string substitution (i.e., replace all appearances of a placeholder in the template with its value).

Note that the template index is 1-indexed.

For example, if the template is "Happy {occasion}, {name}! We hope you have a great day on {date}." and the user input is "1 name=Alice occasion=Birthday date=05/06/2023", the generated message will be "Happy Birthday, Alice! We hope you have a great day on 05/06/2023.".

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains an integer T, the number of templates.
  2. The next T lines each contain a template string that may include placeholders enclosed by curly braces.
  3. The next line contains an integer N, the number of user input strings.
  4. The following N lines each contain a user input string. Each input starts with a template index (1-indexed) followed by one or more key-value pairs in the form key=value, separated by spaces.

outputFormat

The output is printed to standard output (stdout). For each user input, output the customized message on a new line after performing the placeholder substitutions according to the selected template.## sample

3
Happy {occasion}, {name}! We hope you have a great day on {date}.
Dear {name}, wishing you a wonderful {occasion} on {date}.
{date} is a special day for celebrating {occasion} with {name}.
4
1 name=Alice occasion=Birthday date=05/06/2023
2 name=Bob occasion=Anniversary date=12/09/2023
3 name=Charlie occasion=Graduation date=07/08/2023
1 name=Diane occasion=Christmas date=25/12/2023
Happy Birthday, Alice! We hope you have a great day on 05/06/2023.

Dear Bob, wishing you a wonderful Anniversary on 12/09/2023. 07/08/2023 is a special day for celebrating Graduation with Charlie. Happy Christmas, Diane! We hope you have a great day on 25/12/2023.

</p>