-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy path10010 - Where's Waldorf?.cpp
97 lines (82 loc) · 2.41 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
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
86
87
88
89
90
91
92
93
94
95
96
97
/*
Rezwan_4029
AUST , CSE-25
*/
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<sstream>
#include<set>
#include <queue>
#define pb push_back
#define ms(a,v) memset(a,v,sizeof a)
using namespace std;
typedef long long ll;
#define rep(i,n) for( __typeof(n)i = 0 ; i < n ; i++)
#define For(i,n) for( __typeof(n)i = 1 ; i <= n ; i++)
#define forstl(i,n) for(__typeof(n.begin())i = n.begin();i!=n.end();i++)
char grid[57][57],str[57];
int row , col , len ;
bool solve(int x , int y)
{
int j = 0 ;
for(int i = y ; i < col && j < len ; i++,j++ ) if(grid[x][i] != str[j] ) break; // right
if(j == len ) return true ;
j = 0 ;
for(int i = y ; i >= 0 && j < len ; i-- , j++ ) if(grid[x][i] != str[j] ) break; // left
if(j == len ) return true ;
j = 0 ;
for(int i = x ; i < row && j < len ; i++,j++ ) if(grid[i][y] != str[j] ) break; // down
if(j == len ) return true ;
j = 0 ;
for(int i = x ; i >= 0 && j < len ; i-- , j++ ) if(grid[i][y] != str[j] ) break; // up
if(j == len ) return true ;
j = 0 ;
for(int i = x ; i < row && j < len && (y+j) < col ; i++,j++ ) if(grid[i][y+j] != str[j] ) break; // right dia down
if(j == len ) return true ;
j = 0 ;
for(int i = x ; i < row && j < len && (y-j) >= 0 ; i++,j++ ) if(grid[i][y-j] != str[j] ) break; // left dia down
if(j == len ) return true ;
j = 0 ;
for( ; (x-j) >= 0 && (y-j) >= 0 && j < len ; j++ ) if(grid[x-j][y-j] != str[j] ) break; // left dia up
if(j == len ) return true ;
j = 0 ;
for( ; (x+j) < row && (y-j) >= 0 && j < len ; j++ ) if(grid[x+j][y-j] != str[j] ) break; // right dia up
if(j == len ) return true ;
return false;
}
pair<int,int>solve()
{
rep(i,row)rep(j,col){
if( grid[i][j] == str[0] ){
if( solve(i,j) ) return make_pair(i+1,j+1);
}
}
}
int main()
{
int test ;
scanf("%d",&test);
while(test--)
{
scanf("%d %d",&row,&col);
rep(i,row) scanf("%s",grid[i]);
rep(i,row)rep(j,col) grid[i][j] = tolower(grid[i][j]);
int q ;
scanf("%d",&q);
while(q--)
{
scanf("%s",&str);
len = strlen(str);
rep(i,len) str[i] = tolower(str[i]);
pair<int,int>ret = solve();
printf("%d %d\n",ret.first,ret.second);
}
if(test)puts("");
}
}