#K34352. Correct Text Format
Correct Text Format
Correct Text Format
You are given a string s representing a piece of text. Your task is to reformat the text according to the following rules:
- Each sentence is terminated by one of the punctuation marks: \( . \), \( ? \) or \( ! \).
- Any extra spaces should be removed so that there is exactly one space between words and sentences.
- For each sentence, the first letter must be capitalized if it is an alphabetic character.
Note: A sentence is defined as a sequence of characters ending with one of the punctuation marks above, or until the end of the string if no punctuation is present. The punctuation should remain at the end of the sentence.
For example, the string "hello world!" should be reformatted to "Hello world!" and "how are you?i am fine.thanks for asking!" should be reformatted to "How are you? I am fine. Thanks for asking!".
inputFormat
A single string is provided via standard input. The string may contain extra spaces and missing spaces between sentences, and can span multiple lines.
outputFormat
Output the reformatted string to standard output, ensuring that each sentence begins with a capital letter, punctuation is preserved, and extra spaces are removed.## sample
hello world!
Hello world!