Problem Statement
Some writers like to super-emphasize certain points by using multiple exclamation points instead of one. For example, "This cheese is really great!!! I like exclamation points!!!!!!!!" Other times, writers express surprise by mixing exclamation points and question marks. For example, "You really like THIS cheese!?!?!?!!!?".
You are editing a document for publication, and you'd like to get rid of some of the extra punctuation. Wherever you see a group of multiple consecutive exclamation points, replace it with a single exclamation point. Wherever you see a group of multiple consecutive punctuation characters containing at least one question mark and zero or more exclamation points (and no other characters), replace that group with a single question mark. See the examples for further clarification. Return the string after these changes have been made.
Definition
- Class:
- PunctuationCleaner
- Method:
- clearExcess
- Parameters:
- String
- Returns:
- String
- Method signature:
- String clearExcess(String document)
- (be sure your method is public)
Constraints
- document will contain between 1 and 50 characters, inclusive.
- document will contain only letters ('a'-'z', 'A'-'Z'), spaces (' '), question marks ('?'), and exclamation points ('!').
Examples
"This cheese is really great!!!!!"
Returns: "This cheese is really great!"
"You really like THIS cheese!?!?!?!!!?"
Returns: "You really like THIS cheese?"
" !!?X! ?? This is delicious!!! ??!a!?!"
Returns: " ?X! ? This is delicious! ?a?"
Sometimes writers get very carried away. Remember to preserve spaces and other characters from the input.