import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import java.math.*; /** * Finds the first occurrence of a pattern string * in a text string. *
* This implementation uses the Boyer-Moore algorithm (with the bad-character * rule, but not the strong good suffix rule). *
* For additional documentation,
* see Section 5.3 of
* Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
* Copyright © 2000–2017, Robert Sedgewick and Kevin Wayne.
* Last updated: Fri Oct 20 12:50:46 EDT 2017.
*/
import java.text.SimpleDateFormat;
import java.text.NumberFormat;
class main {
static class BoyerMooreStringSearch {
final static int R = 256; // the radix
final int[] right; // the bad-character skip array
final char[] pat; // pattern
BoyerMooreStringSearch(String pat) {
this.pat = toCharArray(pat);
// position of rightmost occurrence of c in the pattern
right = new int[R];
for (int j = 0; j < this.pat.length; j++)
right[this.pat[j] & (R-1)] = j+1;
}
/**
* Returns the index of the first occurrrence of the pattern string
* in the text string.
*
* @param txt the text string
* @return the index of the first occurrence of the pattern string
* in the text string; -1 if no such match
*/
int search(String txt) {
if (txt == null) return -1;
int m = pat.length;
int diff = txt.length()-m;
int skip;
for (int i = 0; i <= diff; i += skip) {
skip = 0;
for (int j = m-1; j >= 0; j--) {
int c = txt.charAt(i+j);
if (pat[j] != c) {
skip = Math.max(1, j - (right[c & (R-1)]-1));
break;
}
}
if (skip == 0) return i;
}
return -1;
}
boolean containedIn(String txt) {
return search(txt) >= 0;
}
}
static char[] toCharArray(String s) {
return asChars(s);
}
// returns snippet IDs
static List
").matcher(page);
List