TopCoder problem "Xox" used in TCHS SRM 14 (Division I Level One)



Problem Statement

    

You are the moderator of a well known forum, and you have noticed that people have been using the word "xox" (quotes for clarity only) very frequently for some time. You would like to measure the scale of that phenomenon by counting the number of letters in the given text that are contained in occurrences of "xox".

All occurrences of the substring "xox" should be considered, even if they are not written as standalone words.

For example, in the sentence:

why the xox u xox

there are six letters that are contained in the two occurrences of "xox", but in:

send xoxoxs to me plz

there are only five letters because the two occurrences of "xox" overlap. Note that the "xox"s in this case are not standalone words.

Given a String text return the number of letters that are contained in occurrences of "xox" as described above.

 

Definition

    
Class:Xox
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 lowercase letters ('a'-'z') and spaces (' ').
 

Examples

0)
    
"why the xox u xox"
Returns: 6
The first example from the problem statement.
1)
    
"send xoxoxs to me plz"
Returns: 5
The second example from the problem statement.
2)
    
" x o x xo x ox "
Returns: 0
This string contains fragments of the word "xox", but it does not contain any occurrences of the entire contiguous string.

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10066&pm=6720

Writer:

slex

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Search, Iteration