package algospot_wildcard;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static int C;
    public static String W;
    public static int N;
    public static String[] WORD;

    public static void main(String[] args) throws Exception {
        FileInputStream fis = new FileInputStream("input.txt");
        System.setIn(fis);

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        StringTokenizer st = new StringTokenizer(br.readLine());
        C = Integer.parseInt(st.nextToken());
        for (int i = 0; i < C; i++) {
            st = new StringTokenizer(br.readLine());
            W = st.nextToken();
            st = new StringTokenizer(br.readLine());
            N = Integer.parseInt(st.nextToken());
            WORD = new String[N];
            for (int j = 0; j < N; j++) {
                st = new StringTokenizer(br.readLine());
                WORD[j] = st.nextToken();
            }

            solve();
        }
    }

    private static void solve() {
        // TODO Auto-generated method stub

    }

}

@@ -110,32 +110,113 @@
 utStreamReader;%0A
+import java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A
 import java.util
@@ -233,16 +233,16 @@
 enizer;%0A
-
 %0Apublic 
@@ -1251,43 +1251,1206 @@
     
-// TODO Auto-generated method stub%0A
+List%3CString%3E list = new ArrayList%3CString%3E();%0A        for (int i = 0; i %3C N; i++) %7B%0A            if (dp(W, WORD%5Bi%5D)) %7B%0A                list.add(WORD%5Bi%5D);%0A            %7D%0A        %7D%0A%0A        // sort%0A        Collections.sort(list);%0A%0A        // print%0A        for (String word : list) %7B%0A            System.out.println(word);%0A        %7D%0A    %7D%0A%0A    private static boolean dp(String w, String word) %7B%0A        int pos = 0;%0A        while (pos %3C w.length() && pos %3C word.length()) %7B%0A            if (w.charAt(pos) == '?' %7C%7C w.charAt(pos) == word.charAt(pos)) %7B%0A                pos++;%0A            %7D else %7B%0A                break;%0A            %7D%0A        %7D%0A%0A        // solve to '?'%0A        if (pos == w.length()) %7B%0A            if (pos == word.length()) %7B%0A                return true;%0A            %7D else %7B%0A                return false;%0A            %7D%0A        %7D else if (w.charAt(pos) == '*') %7B // solve to '*'%0A            String subString = w.substring(pos + 1);%0A            for (int i = 0; pos + i %3C= word.length(); i++) %7B%0A                // search matched case%0A                if (dp(subString, word.substring(pos + i))) %7B%0A                    return true;%0A                %7D%0A            %7D%0A        %7D%0A%0A        return false;
 %0A   

implement for wildcard problems