forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa00422_WordSearchWonder.java
67 lines (59 loc) · 1.7 KB
/
UVa00422_WordSearchWonder.java
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
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 363 (422 - Word-Search Wonder) */
/* SUBMISSION: 11423235 */
/* SUBMISSION TIME: 2013-03-12 01:38:33 */
/* LANGUAGE: 2 */
import java.io.*;
public class UVa00422_WordSearchWonder {
static int[] di = {-1, -1, 0, 0, 1, 1, 1};
static int[] dj = {-1, 1, -1, 1, -1, 0, 1};
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line = in.readLine();
while (true) {
int N = Integer.parseInt(line);
if (N == 0) break;
char[][] puzzle = new char[N][N];
for (int i = 0; i < N; ++i)
puzzle[i] = in.readLine().toCharArray();
while (true) {
String word = in.readLine();
if (word.charAt(0) >= '0' && word.charAt(0) <= '9') {
line = word;
break;
}
boolean found = false;
int rs = 0, cs = 0, rt = 0, ct = 0;
for (int i = 0; i < N && !found; ++i)
for (int j = 0; j < N && !found; ++j)
for (int d = 0; d < 7; ++d) {
found = true;
int nk = 0;
for (int k = 0; k < word.length(); ++k) {
int ni = i + k * di[d];
int nj = j + k * dj[d];
if (ni < 0 || ni >= N || nj < 0 || nj >= N || word.charAt(k) != puzzle[ni][nj]) {
found = false;
break;
}
nk = k;
}
if (found) {
rs = i + 1;
cs = j + 1;
rt = i + nk * di[d] + 1;
ct = j + nk * dj[d] + 1;
break;
}
}
if (!found)
System.out.println("Not found");
else
System.out.println(rs + "," + cs + " " + rt + "," + ct);
}
}
in.close();
System.exit(0);
}
}