BruteForceStringMatching2
发布时间:2020-12-16 18:43:46 所属栏目:大数据 来源:网络整理
导读://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" )
//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))
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |