TopcoderArchiveVisit Topcoder
SRM14 Nov 2007
SRM 376

PunctuationCleaner

Problem statement, definition, constraints, and public examples.

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

  1. "This cheese is really great!!!!!"
    Returns: "This cheese is really great!"
  2. "You really like THIS cheese!?!?!?!!!?"
    Returns: "You really like THIS cheese?"
  3. " !!?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.
Back to all problems