Connection Status:
Competition Arena > CodeRed
TC China 08 - 1B · 2008-11-23 · by Eeyore · Simple Search, Iteration, String Manipulation
Class Name: CodeRed
Return Type: int
Method Name: count
Arg Types: (string)
Problem Statement

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 String, count the number of times "red" appears in it with any capitalization.

Constraints

  • text will contain between 1 and 50 characters, inclusive.
  • text will contain only letters ('A'-'Z', 'a'-'z') and spaces (' ').
Examples
0)
"the detective questioned his credibility"
Returns: 1

The first example from the problem statement.

1)
"Server ERRED in Redirecting Spam"
Returns: 2

The second example from the problem statement.

2)
"Roses are yellow and violets are blue"
Returns: 0
3)
"  read the RED sign   said fReD"
Returns: 2
4)
"redder"
Returns: 1
5)
"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.

Coding Area

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

Submitting as anonymous