private String preProcessing(String p) {
        StringBuilder sb = new StringBuilder();
        boolean haveStar = false;
        for (int i = 0; i < p.length(); i++) {
            if (p.charAt(i) == '?')
                sb.append('?');
            else if (p.charAt(i) == '*')
                haveStar = true;
            else {
                if (haveStar)
                    sb.append('*');
                sb.append(p.charAt(i));
                haveStar = false;
            }
        }
        if (haveStar)
            sb.append('*');
        return sb.toString();
    }