Statistics

Problem Statement for "StringCompressor"

Problem Statement

Class Name: StringCompressor
Method Name: compress
Parameters: String
Returns: String

Implement a class StringCompressor, which contains a method compress.  The
method takes a String as a parameter and replaces all successively duplicated
letters in the String with a number that is the number of duplications followed
by the repeated character.  The method returns this resulting String.

The method signature is (be sure your method is public):
String compress(String toCompress)

TopCoder will ensure the following:
- toCompress is a String of at most 100 letters.  Each character is a lowercase
or capital letter ('a' - 'z' or 'A' - 'Z').

Note:
-This compressor is case sensative.  'A' is a different character than 'a'.
-Single letters (its neighbors are not duplicates of itself) are left alone.

Examples:
"AAAABBBBCDDDDDD" compresses to "4A4BC6D"
"SDFJaAAAAaaaass" compresses to "SDFJa4A4a2s"
"AAAAAAAAAAAf" compresses to "11Af"

Definition

Class:
StringCompressor
Method:
compress
Parameters:
String
Returns:
String
Method signature:
String compress(String param0)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: