1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class Main {
static int C, N;
static int cache[][] = new int[101][101];
static String W, S;
static int match(int w, int s) {
if (cache[w][s] != -1)
return cache[w][s];
int ow = w, os = s;
while (s < S.length() && w < W.length() && (W.charAt(w) == '?' || W.charAt(w) == S.charAt(s))) {
++w;
++s;
}
if (w == W.length())
return cache[ow][os] = (s == S.length() ? 1 : 0);
if (W.charAt(w) == '*')
for (int skip = 0; skip + s <= S.length(); ++skip)
if (match(w + 1, s + skip) == 1)
return cache[ow][os] = 1;
return cache[ow][os] = 0;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
C = Integer.parseInt(br.readLine());
// StringTokenizer st = null;
ArrayList<String> result = new ArrayList<String>();
// ArrayList<String> list = new ArrayList<String>();
StringBuilder sb = new StringBuilder();
for (int c = 0; c < C; c++) {
W = br.readLine();
N = Integer.parseInt(br.readLine());
for (int i = 0; i < N; i++) {
for (int j= 0; j <= 100; j++)
S = br.readLine();
if(match(0, 0)==1) {
result.add(S);
}
}
for (String word : result) {
}
} // tc end
System.out.println(sb);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
정리해야함 코드도 내용도
'알고리즘 ' 카테고리의 다른 글
[JAVA] 단체사진 찍기 (2017 카카오코드 본선) (0) | 2022.06.18 |
---|---|
SCC - Tarjan (타잔 알고리즘) (0) | 2019.07.11 |
백준 2042 : 구간 합 구하기 - 세그먼트 트리 (0) | 2019.05.25 |
백준 1941 : 소문난 칠공주 (0) | 2019.05.21 |
SCC - kosaraju (0) | 2019.05.21 |