#C220. Reverse the Words in a Sentence
Reverse the Words in a Sentence
Reverse the Words in a Sentence
Given a sentence, your task is to reverse the order of the words. If the sentence ends with a punctuation mark (specifically '.', '!', or '?'), you must preserve it at the end after reversing the words. For example, given the sentence "Hello World!", the output should be "World Hello!".
Note: The sentence may contain multiple words separated by spaces.
inputFormat
Input is provided via stdin as a single line representing the sentence. The sentence can include spaces and possibly end with punctuation.
outputFormat
Output the reversed sentence via stdout following the rules provided. Make sure that if the input ends with a punctuation mark ('.', '!', or '?'), it appears at the end of the reversed sentence.## sample
Hello World
World Hello