#K56867. String Transformation
String Transformation
String Transformation
Given a string, transform it so that each word starts with an uppercase letter and all subsequent characters are lowercase. Also, eliminate any extra spaces so that there is exactly one space between words. For instance, the input hello world THIS is a TEST
should produce Hello World This Is A Test
.
Note: If the input is an empty string, the output should also be an empty string.
The transformation can be formalized as follows:
[ \text{Output} = \text{Join}_{word \in \text{Split}(\text{Trim}(s))}\Big(\text{Capitalize}(word)\Big) ]
inputFormat
The input consists of a single line read from STDIN, containing the string to be transformed. The string may include leading, trailing, or extra spaces between words.
outputFormat
Output the transformed string to STDOUT. Each word in the output should start with an uppercase letter followed by lowercase letters, and words should be separated by a single space. If the input is empty, output an empty string.
## samplehello world THIS is a TEST
Hello World This Is A Test