TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

Case

Problem statement, definition, constraints, and public examples.

Problem Statement

A TopCoder member NorthPole created a typing robot named Typo. You insert a disk with a text file into his mouth and he types the text file from this disk on the keyboard. Unfortunately, there is a malfunction in his software: he types ';' (semi-colon) instead of the space character. Also, there is a malfunction in his hardware: there is a delay in pressing the Shift button, so that the next character after the required one is typed with the Shift button. For example: instead of "NorthPole", Typo types "nOrthpOle".

Your task is, given a String typed by Typo, recover the original String. Assume that the original text has only letters, commas, periods and spaces. For examples, if he types ':' it means that he meant to type the space (' ') and the previous letter is shifted. Assume, that the last character of the original String doesn't require the Shift button (i.e. it is either a lower case letter [a-z], a comma, a period, or a space character.

Definition

Class:
Case
Method:
recover
Parameters:
String
Returns:
String
Method signature:
String recover(String text)
(be sure your method is public)

Notes

  • If you hold down shift and press space, you still get a space. In other words, shift does not effect the space character.

Constraints

  • text will consist only of letters [A-Z] and [a-z] inclusive, and the following characters: .,:;<>
  • text will have between 0 and 50 characters inclusive
  • if text has at least one character, then the first character will be a lower-case letter [a-z] or one of ',', '.' or ';' (as Typo never presses the Shift button for the first character)

Examples

  1. "tOpcOder"
    Returns: "TopCoder"
    The two 'O's are capitalized, but that is with the shift character delayed.
  2. "uSA<;and;rUssia"
    Returns: "USA, and Russia"
    Note that '<' is a shifted comma.
  3. "nEw;yOrk;;;aND:;;bOston"
    Returns: "New York   AND   Boston"
    Here, a ':' occurs where a ';' is shifted.
  4. ""
    Returns: ""
  5. ";A"
    Returns: " a"
    Note that a shifted space is still a space.
Back to all problems