#C7573. Normalize Sentences
Normalize Sentences
Normalize Sentences
You are given a text string that may contain multiple sentences. Each sentence is defined as a string ending with one of the punctuation marks: . ! ?. Your task is to write a program that normalizes the text by ensuring the following:
- Each sentence starts with a capital letter.
- Each sentence ends with a single period (.).
- Any extraneous whitespace is removed.
- Any punctuation characters (other than the sentence-ending ones) are removed from the sentence.
If the input is not a valid string, the program should output undefined
(as a string). In addition, if a sentence does not already end with a punctuation mark, append a period at the end.
The normalization for each sentence can be described mathematically by the formula:
$$\text{NormalizedSentence} = Capitalize(\text{Trim}(\text{RemoveExtraSpaces}(\text{RemovePunctuation}(sentence))) )$$Output the complete normalized text where sentences are separated by a period and a space.
inputFormat
The input consists of a single text string provided via standard input (stdin). The string may include newline characters and irregular spacing.
outputFormat
The output should be a single normalized string printed to standard output (stdout) following the rules described above.
## samplethis is a sentence! here is another one? and here's a third sentence. multiple lines, irregular spacing!
This is a sentence. Here is another one. And heres a third sentence. Multiple lines irregular spacing.