#K43887. Capitalize Each Word
Capitalize Each Word
Capitalize Each Word
You are given a string consisting of alphabetic characters and whitespace. Your task is to transform this string such that each word has its first letter capitalized and all remaining letters in lowercase. The structure and spacing of the input string must be preserved exactly as it is.
Note: A word is defined as a maximal sequence of alphabetic characters. Characters that are not letters (including spaces) should remain unchanged.
For example, given the input hello world
, the output should be Hello World
.
Constraints: The input string can include leading, trailing, and multiple spaces between words.
The transformation can be described by the following approach: $$ \text{For each character } c \text{ in the input string:}\ \quad \text{if } c \text{ is alphabetic and it is the start of a new word, convert } c \text{ to uppercase;} \ \quad \text{if } c \text{ is alphabetic and not the start of a new word, convert } c \text{ to lowercase;} \ \quad \text{otherwise, keep } c \text{ unchanged.} $$
inputFormat
The input consists of a single line string read from standard input (stdin
). This string may contain leading, trailing, or multiple spaces between words.
outputFormat
Output the transformed string, where each word is capitalized as described, to standard output (stdout
).
hello world
Hello World