시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
8 초 | 1024 MB | 59 | 40 | 38 | 84.444% |
As practice will tell you, the English rules for comma placement are complex, frustrating, and often ambiguous. Many people, even the English, will, in practice, ignore them, and, apply custom rules, or, no rules, at all.
Doctor Comma Sprinkler solved this issue by developing a set of rules that sprinkles commas in a sentence with no ambiguity and little simplicity. In this problem you will help Dr. Sprinkler by producing an algorithm to automatically apply her rules.
Dr. Sprinkler’s rules for adding commas to an existing piece of text are as follows:
As an example, consider the text
please sit spot. sit spot, sit. spot here now here.
Because there is a comma after spot
in the second sentence, a comma should be added after spot
in the third sentence as well (but not the first sentence, since it is the last word of that sentence). Also, because there is a comma before the word sit
in the second sentence, one should be added before that word in the first sentence (but no comma is added before the word sit
beginning the second sentence because it is the first word of that sentence). Finally, notice that once a comma is added after spot
in the third sentence, there exists a comma before the first occurrence of the word here
. Therefore, a comma is also added before the other occurrence of the word here
. There are no more commas to be added so the final result is
please, sit spot. sit spot, sit. spot, here now, here.
The input contains one line of text, containing at least 2 characters and at most 1 000 000 characters. Each character is either a lowercase letter, a comma, a period, or a space. We define a word to be a maximal sequence of letters within the text. The text adheres to the following constraints:
Display the result after applying Dr. Sprinkler’s algorithm to the original text.
please sit spot. sit spot, sit. spot here now here.
please, sit spot. sit spot, sit. spot, here now, here.
one, two. one tree. four tree. four four. five four. six five.
one, two. one, tree. four, tree. four, four. five, four. six five.