字符串匹配——朴素算法

来源:互联网 发布:声卡mc录音软件 编辑:程序博客网 时间:2024/06/05 01:54
import java.util.*;public class NaiveStringMatcher{public static char[] t = {'a', 'c', 'a', 'a', 'b', 'c'};public static char[] p = {'a', 'a', 'b'};public static void main(String[] args){int n = t.length;int m = p.length;char[] tmp;for (int s = 0; s <= n-m; s++){tmp = Arrays.copyOfRange(t, s, n-m+s);if (Arrays.equals(p, tmp)){System.out.println("Pattern occurs with shift" + s);}}}}

0 0
原创粉丝点击