Connection Status:
Competition Arena > OxToTiger
SRM 823 · 2022-02-01 · by misof · Brute Force, Simple Search, Iteration, String Manipulation
Class Name: OxToTiger
Return Type: String
Method Name: rewrite
Arg Types: (string)
Problem Statement

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.

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
0)
"ox"
Returns: "tiger"
1)
"fox"
Returns: "fox"

Don't replace "ox" if it isn't a stand-alone word.

2)
" 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.

3)
"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.

4)
"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.

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

Coding Area

Language: C++17 · define a public class OxToTiger with a public method string rewrite(string message) · 41 test cases · 2 s / 256 MB per case

Submitting as anonymous