//The brute-force algorithm is to solve the problem of //counting,in a given text,the number of substrings that starts //with an A and ends with a B.
//For example,there are four such substrings in CABAAXBYA.
package main
import (
"fmt"
)
func StringMatching2(text []rune) int {
n := len(text)
count := 0
for i := 0; i <= n-2; i++ {
for j := 0; i+j < n; {
if j == 0 {
if text[i+j] == 'A' {
j++
continue
} else {
break
}
} else {
if text[i+j] == 'B' {
count++
}
j++
}
}
}
return count
}
func main() {
text := []rune("CABBBBB")
fmt.Println(StringMatching2(text))
}