CodeRed
TC China 08 - 1B · 2008-11-23 · by Eeyore
Problem Statement
We are looking for occurrences of the string "red" in a piece of text. For example, in the text
the detective questioned his credibility
we find "red" inside the word "credibility".
Capitalization doesn't matter, so in the text
Server ERRED in Redirecting Spam
we find "red" at the end of "ERRED", as well as at the beginning of "Redirecting".
Given a
Constraints
- text will contain between 1 and 50 characters, inclusive.
- text will contain only letters ('A'-'Z', 'a'-'z') and spaces (' ').
"the detective questioned his credibility" Returns: 1
The first example from the problem statement.
"Server ERRED in Redirecting Spam" Returns: 2
The second example from the problem statement.
"Roses are yellow and violets are blue" Returns: 0
" read the RED sign said fReD" Returns: 2
"redder" Returns: 1
"pure delight" Returns: 0
Note that "re d" is not counted as an occurrence of "red".
Submissions are judged against all 72 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CodeRed with a public method int count(string text) · 72 test cases · 2 s / 256 MB per case