BruteForceStringMatching2
来源:互联网 发布:淘宝网韩版针织开衫 编辑:程序博客网 时间:2024/06/10 06:09
//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 mainimport ( "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))}
0 0
- BruteForceStringMatching2
- Hibernate缓存管理
- 第五周项目一:体验常成员函数
- jfreechart折线图示例
- c++模板元编程七:类型判断的traits类
- jQuery Ajax 实例 ($.ajax、$.post、$.get)
- BruteForceStringMatching2
- 使用Camera Calibration Toolbox for Matlab进行摄像机标定
- Mac OS X的入门文档
- android Toobar的一个简单封装
- hihoCoder#1051 : 补提交卡
- 大数据学习笔记2--hdfs工作原理及源码分析
- shell语法简介
- 深拷贝,浅拷贝
- 用c实现的fft和ifft