TopCoder problem "CodeRed" used in TC China 08 - 1B (Division I Level One)



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

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)
    
"  read the RED sign   said fReD"
Returns: 2
3)
    
"pure delight"
Returns: 0
Note that "re d" is not counted as an occurrence of "red".
4)
    
"re"
Returns: 0

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=2242

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13674&pm=2242

Writer:

Eeyore

Testers:

PabloGilberto , brett1479 , Olexiy , marian , ivan_metelsky , ged

Problem categories:

Simple Search, Iteration, String Manipulation