Connection Status:
Competition Arena > CultureShock
SRM 216 · 2004-10-18 · by dgarthur · Simple Search, Iteration, String Parsing
Class Name: CultureShock
Return Type: String
Method Name: translate
Arg Types: (string)
Problem Statement

Problem Statement

Bob and Doug have recently moved from Canada to the United States, and they are confused by this strange letter, "ZEE". They need your assistance. Given a String text, replace every occurrence of the word, "ZEE", with the word, "ZED", and return the result.

Note that if "ZEE" is just part of a larger word (for example, "ZEES"), it should not be altered.

Constraints

  • text will contain between 1 and 50 characters inclusive.
  • Each character in text will either be a space (' '), or a capital letter ('A'-'Z').
  • text will have precisely one space between consecutive words, and it will have no leading or trailing spaces.
Examples
0)
"THE TWENTY SIXTH LETTER OF THE ALPHABET IS ZEE"
Returns: "THE TWENTY SIXTH LETTER OF THE ALPHABET IS ZED"

There is precisely one occurrence of "ZEE" in this line of text, so it should be replaced with "ZED".

1)
"ZEE"
Returns: "ZED"
2)
"SPELLING IN ENGLISH IS EZEE"
Returns: "SPELLING IN ENGLISH IS EZEE"

The "ZEE" at the end of this line should not be altered since it is part of a larger word.

3)
"ZEE ZEE ZED ZEDS ZEE ZEES"
Returns: "ZED ZED ZED ZEDS ZED ZEES"
4)
"MJXVTE NHACJDEZ"
Returns: "MJXVTE NHACJDEZ"

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

Coding Area

Language: C++17 · define a public class CultureShock with a public method string translate(string text) · 65 test cases · 2 s / 256 MB per case

Submitting as anonymous