TopcoderArchive
Archive23 Nov 2008
TC China 08 - 1B

CodeRed

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
CodeRed
Method:
count
Parameters:
String
Returns:
int
Method signature:
int count(String text)
(be sure your method is public)

Constraints

  • text will contain between 1 and 50 characters, inclusive.
  • text will contain only letters ('A'-'Z', 'a'-'z') and spaces (' ').

Examples

  1. "the detective questioned his credibility"
    Returns: 1
    The first example from the problem statement.
  2. "Server ERRED in Redirecting Spam"
    Returns: 2
    The second example from the problem statement.
  3. "  read the RED sign   said fReD"
    Returns: 2
  4. "pure delight"
    Returns: 0
    Note that "re d" is not counted as an occurrence of "red".
  5. "re"
    Returns: 0
Back to all problems