-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path10010-Where's Waldorf?.cpp
45 lines (43 loc) · 1.33 KB
/
10010-Where's Waldorf?.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
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> dirs = {{0,1},{1,0},{-1,0},{0,-1},{-1,-1},{-1,1},{1,-1},{1,1}};
int main()
{
int t,n,m,q;
string in;
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
vector<string> grid;
for(int i=0;i<n;i++){
cin >> in;
transform(in.begin(),in.end(),in.begin(),::tolower);
grid.push_back(in);
}
scanf("%d",&q);
for(int i=0;i<q;i++){
cin >> in;
transform(in.begin(),in.end(),in.begin(),::tolower);
bool found = false;
for(int i=0;i<n&&!found;i++){
for(int j=0;j<m&&!found;j++){
for(auto& dir : dirs){
int x=i,y=j,cur=0;
while(cur<in.length()){
if(x<0||y<0||x>=n||y>=m
|| grid[x][y] != in[cur]) break;
if(++cur == in.length())
found = true;
x+=dir[0], y+=dir[1];
}
if(found){
printf("%d %d\n",i+1,j+1);
break;
}
}
}
}
}
if(t) printf("\n");
}
}