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
"why the xox u xox"
Returns: 6
The first example from the problem statement.
"send xoxoxs to me plz"
Returns: 5
The second example from the problem statement.
" 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.
"thats one xoxo for xox one xoxox xoxo for xoxoxox"
Returns: 21
"xox"
Returns: 3
"oxxoxoxo"
Returns: 5
"axoxoxoxb"
Returns: 7
"ooxxxoooooooxx"
Returns: 0
"xoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxo"
Returns: 49
"xoooxxxooo oxo oxdxgxoxfxoxoxooo xxoxoxoxoxoxoxoxo"
Returns: 23
"x"
Returns: 0
"o"
Returns: 0
"ox"
Returns: 0
"xo"
Returns: 0
"oxo"
Returns: 0
"xoxoxxxoxoxxxoxoxxxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox"
Returns: 46
"oxxo"
Returns: 0
"xoxoxdxoaoxxxoxcxxxoxoxocoxoxoxoxodoxoxoxodoxoxox"
Returns: 30
"mxxxxotooooxox"
Returns: 3
"xxtllafooooaoicoooxoyxxxdkoxoxnoxomwpxoxxtxqx"
Returns: 6
" rooxxxxxyovoouox xtxoohoxtxoodfxoxxxx"
Returns: 3
"oxmooxzpjooxokoxxoozooooxjooxaxop"
Returns: 0
"xxoxowaoxoxooxolojxoxxo"
Returns: 9
"oxwxbxooxoxonxcxxh"
Returns: 3
"oxgyo"
Returns: 0
" xtxo xxoboiaoxoxmxsxooooxxxoloxwqoxoxnoxxtbxoob"
Returns: 6
"xookixoxxooxnxx xfxoyoxooooxbxroocoxooxxx"
Returns: 3
"opxodxoxkx"
Returns: 3
"xxxoxsxojxovoaoooxxx"
Returns: 3
"qgroajxogxodosxiodcotyvoxedxxzpoovxoxxxxx"
Returns: 3
"wuoxxfooeuoxoxoxo xxxxooxooooodxx xexxxoxu"
Returns: 8
"aq"
Returns: 0
"xojoxoxoxgyoooxxxxhoxooorx"
Returns: 5
"xaolo"
Returns: 0
"ojxloozxxxuiooxoxoxyooxxoooosooxooxxxxjxjxg eoi"
Returns: 5
"xqoxokxnoxuxhodozpkxwxoxiotoxxokoo"
Returns: 3
"xoioorxjoxot"
Returns: 0
"sxbexxojoxoooxvx"
Returns: 0
"xxoxooxoohlx"
Returns: 3
"ogxoxxx"
Returns: 3
"fsfoxoxpox oxxkxxjxoo xexit"
Returns: 3
"pxoojoxxqxkho"
Returns: 0
"lsorfoxxyoxxvoioeorroxpowxoxjucoxjobxxoxoxhx x"
Returns: 8
"xxxaox"
Returns: 0
"oxozuvotxooeoxoxsxocoohxfxooxxxxxoxxd"
Returns: 6
"cxxofxooxxxpootxxx"
Returns: 0
"iwxxxoxozjoxxxoisoloj"
Returns: 3
"toxxdoocobsuofosoxooqpoxoxxfxxnotonxo"
Returns: 3
"xoxxox"
Returns: 6
"h"
Returns: 0
"x"
Returns: 0
"mamaxoxoxox"
Returns: 7
"w"
Returns: 0
"xoxo"
Returns: 3
" "
Returns: 0
"xox"
Returns: 3
"axox"
Returns: 3
"xoxos toxoxpopoxoxoxxoxooxxosdxxxoxoxoxo me oxl"
Returns: 21
"xoxoxoxoxoxoxoxoxooxoxoxooxoxoxoooxoxox"
Returns: 32
"xoxa"
Returns: 3
"xxoxxxoxx x xoxoxox xoxox xo xoxoxoxoxox xo x"
Returns: 29
"dxox"
Returns: 3
"xxd"
Returns: 0
"xdxoxxoxoxxasoxxoxoxxfeoxxoxoxxoxoxxoxoxxoxoxxoxox"
Returns: 38