(String[] args)
| 6 | static StringBuilder match_index; |
| 7 | |
| 8 | public static void main(String[] args) { |
| 9 | |
| 10 | T = "ABABABABBABABABABC"; |
| 11 | P = "ABABABC"; |
| 12 | |
| 13 | N = P.length(); |
| 14 | fail = new int[N]; |
| 15 | makeFail(); // fail 함수 만들기 |
| 16 | |
| 17 | match_index = new StringBuilder(); |
| 18 | System.out.println(kmp()); // kmp 함수 : 문자열 T 안에 패턴 P가 몇 번 나타나는지 찾기 |
| 19 | System.out.print(match_index.toString()); // 패턴이 일치한 시작 인덱스 찾기 |
| 20 | } |
| 21 | |
| 22 | static void makeFail() { |
| 23 | for (int i = 1, j = 0; i < N; i++) { |