Fenergo | online | Correct punctuation
Anonymous User
191

Given a text consisting of English letters, spaces, and punctuation marks ,, ., ?, !, your task is to correct the following mistakes in the text:
There shouldn't be a space before any punctuation marks;
Each punctuation mark which is not the last character of the text should be followed by a space.

Example
For text = "This sentence contains both lowercase and uppercase English letters , punctuation marks,and spaces.", the output should be punctuationMistakes(text) = "This sentence contains both lowercase and uppercase English letters, punctuation marks, and spaces.".

Input/Output
[execution time limit] 3 seconds (cs)
[input] string text
It is guaranteed that there are no two consecutive spaces in the text. It is also guaranteed that for each pair of punctuation marks, there is at least one letter between them.
Guaranteed constraints:
1 ≤ text.length ≤ 500.
[output] string

Comments (1)