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?"
"a??a ?!a a!?b b!?!C C?!!D D?!?EE ??? FF!!! !???!"
Returns: "a?a ?a a?b b?C C?D D?EE ? FF! ?"
" a b c A B ! !!C!!! ! ! !C ?!!? ?!? ??"
Returns: " a b c A B ! !C! ! ! !C ? ? ?"
" !!?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.
"??????????????????"
Returns: "?"
"?"
Returns: "?"
"!"
Returns: "!"
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Returns: "!"
"?!!!!!!!!!!!!!!!!!"
Returns: "?"
"!!!!!!!!!!!!?"
Returns: "?"
"!?"
Returns: "?"
"?!"
Returns: "?"
"!!"
Returns: "!"
"Aso!idjf ?owiej !?foj w!?efoji o!!wIEJ"
Returns: "Aso!idjf ?owiej ?foj w?efoji o!wIEJ"
"! !! !!! !!!! ? ?? ??? ???? !? !!? !?! ?!!"
Returns: "! ! ! ! ? ? ? ? ? ? ? ?"
"!a !a! a!!! !!!!a b? c?? ?c?? ??C? !!?e !?!f d?!!"
Returns: "!a !a! a! !a b? c? ?c? ?C? ?e ?f d?"
"ALKJOSDIJFI ABC ZZZ a z aaa zzz"
Returns: "ALKJOSDIJFI ABC ZZZ a z aaa zzz"
"a"
Returns: "a"
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Returns: "!"
" !!! ?? a "
Returns: " ! ? a "
"?!? ?!? ???????????? ?"
Returns: "? ? ? ?"
"! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! "
Returns: "! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! "
"?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!"
Returns: "?"
"??A!EXCLAMATION dkkdkii!?lol! ! ? !a ? a?! ??"
Returns: "?A!EXCLAMATION dkkdkii?lol! ! ? !a ? a? ?"
"!!!HOORAY FOR THIS SENTENCE!!!"
Returns: "!HOORAY FOR THIS SENTENCE!"
"test"
Returns: "test"
"a!!!!!!"
Returns: "a!"
"!?Go!!! S!!!OC!!?!?!CER !!!"
Returns: "?Go! S!OC?CER !"
" ?? ?! ?!?!a? ??!!?!ks??! !"
Returns: " ? ? ?a? ?ks? !"
"?????"
Returns: "?"
"You really like THIS cheese!!!!??? ?? ?!?!?!!!?"
Returns: "You really like THIS cheese? ? ?"
" !!?X! ?? This is delicious!!! ??!a!?!"
Returns: " ?X! ? This is delicious! ?a?"
"ae! ae! ae!! ae!! ae!"
Returns: "ae! ae! ae! ae! ae!"
"??!X?!!?! A!!! B?? ??C!!?"
Returns: "?X? A! B? ?C?"
"aaa?????"
Returns: "aaa?"
"?!?!?!? !? asddd ?!?A?!C?A !!!!??? ???!!! ? ? ! !"
Returns: "? ? asddd ?A?C?A ? ? ? ? ! !"
"Bleh?!!!!"
Returns: "Bleh?"
" ??! teste tt? !! ??? !!?! "
Returns: " ? teste tt? ! ? ? "
"a!!! b!!? c!?! d?!! e!?? f?!? g??! l!!! p???! p???"
Returns: "a! b? c? d? e? f? g? l! p? p?"
"! !"
Returns: "! !"
"a!!?!!"
Returns: "a?"
" !X? "
Returns: " !X? "
"a?"
Returns: "a?"
" "
Returns: " "