TopcoderArchiveVisit Topcoder
SRM25 Jun 2013
SRM 598

ErasingCharacters

Problem statement, definition, constraints, and public examples.

Problem Statement

Fox Ciel received a string as a birthday present. However, the string was too long for her, so she decided to make it shorter by erasing some characters.

The erasing process will look as follows:
  1. Find the smallest i such that the i-th character and the (i+1)-th character of the string are same.
  2. If there is no such i, end the process.
  3. Remove the i-th and the (i+1)-th character of the string, and repeat from 1.


For example, if she receives "cieeilll", she will change the string as follows: "cieeilll" -> "ciilll" -> "clll" -> "cl". You are given a String s. Return the string she will get after she erases characters as described above.

Definition

Class:
ErasingCharacters
Method:
simulate
Parameters:
String
Returns:
String
Method signature:
String simulate(String s)
(be sure your method is public)

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character in s will be a lowercase letter ('a'-'z').

Examples

  1. "cieeilll"
    Returns: "cl"
    This is the example from the statement.
  2. "topcoder"
    Returns: "topcoder"
    She won't erase any characters at all.
  3. "abcdefghijklmnopqrstuvwxyyxwvutsrqponmlkjihgfedcba"
    Returns: ""
  4. "bacaabaccbaaccabbcabbacabcbba"
    Returns: "bacbaca"
  5. "eel"
    Returns: "l"
Back to all problems