#C2672. Reverse Words in a Sentence
Reverse Words in a Sentence
Reverse Words in a Sentence
Given a sentence, reverse each word individually while maintaining the original word order and ensuring that the first letter of each word is capitalized (with the remaining letters in lowercase). The transformation works as follows:
- For each word, take the substring starting from the second character, reverse it, then append the first character at the end.
- After the above step, convert the first letter of the resulting word to uppercase and the rest to lowercase.
- If the input is empty or consists of only whitespace, the output should be an empty string.
Example:
Input: Hello World Output: Olleh Dlrow
Your task is to implement a solution that reads a sentence from stdin
and prints the transformed sentence to stdout
.
inputFormat
The input consists of a single line containing a sentence. The sentence may be empty or contain extra spaces. Words are separated by whitespace.
outputFormat
The output is the transformed sentence where each word has been processed by reversing the substring from the second character onward, appending the first character at the end, and then capitalizing the first letter (with the remaining letters in lowercase).
## sampleHello
Olleh