-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOGGLE.cpp
More file actions
52 lines (49 loc) · 1.08 KB
/
Copy pathBOGGLE.cpp
File metadata and controls
52 lines (49 loc) · 1.08 KB
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
#include <iostream>
#include <string>
using namespace std;
const int dx[8] = { -1,-1,-1,1,1,1,0,0 };
const int dy[8] = { -1,0,1,-1,0,1,-1,1 };
char board[5][5];
bool hasWord(int y, int x, const string& word) {
if (y < 0 || y >= 8 || x < 0 || x >= 8)return false;
if (board[y][x] != word[0])return false;
if (word.length() == 1)return true;
for (int d = 0; d < 8; d++) {
int nextY = y + dy[d];
int nextX = x + dx[d];
if (hasWord(nextY, nextX, word.substr(1)))
return true;
}
return false;
}
int main() {
int t; // Å×½ºÆ® ÄÉÀ̽º ¼ö
cin >> t;
while (t--) {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
cin >> board[i][j];
}
}
int wordNum = 0;
cin >> wordNum;
string s;
for (int i = 0; i < wordNum; i++) {
cin >> s;
bool check = false;
for (int x = 0; x < 5; x++) {
for (int y = 0; y < 5; y++) {
if (check == true) {
x = 10;
break;
}
check = hasWord(y, x, s);
}
}
cout << s << (check ? " YES" : " NO");
cout << endl;
}
}
cin >> t;
return 0;
}