TopcoderARCHIVE
Archive/Problems/OxToTiger
SRM · Problem 17373

OxToTiger

Problem statement, definition, constraints, and public examples.

Problem Statement

To celebrate the Lunar New Year that starts the Year of the Tiger, the problems in this set feature tigers.


I want to send my friends a message with best wishes for the upcoming year of the tiger. As I'm lazy, I just found a similar message I sent last year and now I just need to update it.

You are given the String message. Please replace all occurrences of the word "ox" with the word "tiger" and return the updated message.

Make sure to only replace whole words. Do not replace "ox" if it occurs as a part of a longer contiguous block of letters.

Definition

Class:
OxToTiger
Method:
rewrite
Parameters:
String
Returns:
String
Method signature:
String rewrite(String message)
(be sure your method is public)

Constraints

  • message will contain between 0 and 100 characters, inclusive.
  • Each character of message will be a lowercase English letter ('a'-'z') or a space (' ').

Examples

  1. "ox"
    Returns: "tiger"
  2. "fox"
    Returns: "fox"
    Don't replace "ox" if it isn't a stand-alone word.
  3. " ox  "
    Returns: " tiger  "
    This message starts with one space and ends with two spaces. All characters other than the "ox" you are replacing must be preserved exactly.
  4. "the ox the ox the ox and the fox in the box"
    Returns: "the tiger the tiger the tiger and the fox in the box"
    Remember to replace all occurrences of the word "ox", not just some of them.
  5. "the plural of ox is oxen"
    Returns: "the plural of tiger is oxen"
    We aren't doing anything smart, we are literally just replacing "ox" with "tiger". The "oxen" should remain unchanged.
← All problems