-
Notifications
You must be signed in to change notification settings - Fork 14
/
10010.cpp
85 lines (82 loc) · 1.81 KB
/
10010.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define FOI(i, A, B) for (i = A; i <= B; i++)
#define FOD(i, A, B) for (i = A; i >= B; i--)
string low(string S) {
int i, L = S.length() - 1;
FOI(i, 0, L)
S[i] = tolower(S[i]);
return S;
}
int main(){
//freopen("testI.txt", "r", stdin);
//freopen("testO.txt", "w", stdout);
int T;
cin >> T;
while (T--) {
int M, N;
int i, j, k;
cin >> M >> N;
string str[M];
FOI(i, 0, M-1) {
cin >> str[i];
str[i] = low(str[i]);
}
int Q;
cin >> Q;
while (Q--) {
string S;
cin >> S;
S = low(S);
int L = S.length();
bool flag = false;
FOI(i, 0, M-1) {
FOI(j, 0, N-1) {
string A = "", B = "", C = "", D = "", E = "", F = "", G = "", H = "";
FOI(k, 0, L-1) {
if (j + k < N) A += str[i][j + k];
if (i + k < M && j + k < N) B += str[i + k][j + k];
if (i + k < M) C += str[i + k][j];
if (i + k < M && j - k >= 0) D += str[i + k][j - k];
if (j - k >= 0) E += str[i][j - k];
if (i - k >= 0 && j - k >=0) F += str[i - k][j - k];
if (i - k >= 0) G += str[i - k][j];
if (i - k >= 0 && j + k < N) H += str[i - k][j + k];
}
if (A == S || B == S || C == S || D == S || E == S || F == S || G == S || H == S) {
flag = true;
break;
}
}
if (flag) break;
}
cout << i + 1 << " " << j + 1 << endl;
}
if (T) cout << endl;
}
return 0;
}