#K13596. Color Sentence
Color Sentence
Color Sentence
Problem Statement:
You are given a space‐separated list of colors on the first line and, on the second line, a sentence composed of words separated by spaces. Your task is to color each word in the sentence using a cyclic pattern from the provided colors.
For each word, append the corresponding color in parentheses immediately after the word. The color for each word is chosen in sequence from the color list and wraps around if the number of words exceeds the number of colors.
Example: If the colors are "red blue green" and the sentence is "Hello this is a test", the output should be:
Hello(red) this(blue) is(green) a(red) test(blue)
Implement a solution that reads from standard input (stdin) and writes the result to standard output (stdout).
inputFormat
Input Format:
- The first line contains a space-separated list of colors.
- The second line contains a sentence with words separated by spaces.
For example:
red blue green Hello this is a fun chatbot feature
outputFormat
Output Format:
Output a single line where each word from the input sentence is followed immediately by its corresponding color in the format: word(color)
. Words should be separated by a single space.
For example:
Hello(red) this(blue) is(green) a(red) fun(blue) chatbot(green) feature(red)## sample
red blue green
Hello this is a fun chatbot feature
Hello(red) this(blue) is(green) a(red) fun(blue) chatbot(green) feature(red)