送分题,将字符串split转字符数组即可,然后进行遍历匹配。
Go版本:
import (
"strings"
)
func findOcurrences(text string, first string, second string) []string {
// 字符串匹配
// pattern:=first+" "+second
var third []string
arr:=strings.Split(text," ")
for i:=1;i<len(arr)-1;i++{
if arr[i-1]==first && arr[i]==second {
third=append(third,arr[i+1]);
}
}
return third;
}
网友评论