Connection Status:
Competition Arena > ErasingCharacters
SRM 598 · 2013-06-25 · by rng_58 · Simulation
Class Name: ErasingCharacters
Return Type: String
Method Name: simulate
Arg Types: (string)
Problem Statement

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.

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character in s will be a lowercase letter ('a'-'z').
Examples
0)
"cieeilll"
Returns: "cl"

This is the example from the statement.

1)
"topcoder"
Returns: "topcoder"

She won't erase any characters at all.

2)
"abcdefghijklmnopqrstuvwxyyxwvutsrqponmlkjihgfedcba"
Returns: ""
3)
"bacaabaccbaaccabbcabbacabcbba"
Returns: "bacbaca"
4)
"eel"
Returns: "l"

Submissions are judged against all 33 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ErasingCharacters with a public method string simulate(string s) · 33 test cases · 2 s / 256 MB per case

Submitting as anonymous