-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10010.cpp
More file actions
149 lines (134 loc) · 4.18 KB
/
10010.cpp
File metadata and controls
149 lines (134 loc) · 4.18 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/****** BISMILLAHIR RAHMANIR RAHIM ********\
/*********************************************************************\
# |--\ /--| | | | ----- /-------------\ #
# | \ / | | | | / | | #
# | \ / | | | | / | | #
# | | | | |/ | | #
# | | | | |\ | | #
# | | | | | \ | | #
# | | \ / | \ | | #
# --- --- \______ / | ----- ----- #
# #
# #
# #
# codeforces = Mukit09 #
# topcoder = Mukit09 #
# codechef = mukit_mkbs #
# uva = Mukit09 #
# spoj = mkbs_cse09 #
# CSE, CUET #
# facebook : https://www.facebook.com/hesitated.mkbs?ref=tn_tnmn #
# #
# #
\*********************************************************************/
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
// Define Some Variables
#define eps 1e-14
#define si 55
#define pi acos(-1.0)
#define inf (1<<30)-1
#define mod 1000000000 //10^9
//Define Some Functions
#define even(a) ((a)%2==0)
#define odd(a) ((a)%2==1)
#define max(a,b) (a>b ?a:b)
#define min(a,b) (a<b ?a:b)
#define pb push_back
#define mpair make_pair
#define sqr(a)((a)*(a))
#define area(x1,y1,x2,y2,x3,y3) (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) //Area of a triangle
#define dist(x1,y1,x2,y2) (sqr(x1-x2)+sqr(y1-y2)) //Distance between two points
#define mem(a,v) memset(a,v,sizeof(a))
inline bool compare( double a, double b ) { return fabs( a-b ) < eps ; }
#define fr(i,a,b) for(i=a;i<=b;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>=b;i--)
typedef long long i64;
int dx[]={0,0,1,-1,1,-1,1,-1};
int dy[]={1,-1,0,0,-1,1,1,-1};
int i,j,l,n,cs=1,cnt,sm,fg,m;
char ch[si][si],st[si*si];
int valid(int x,int y,int ind)
{
int i,tmpx,tmpy,tmpInd;
rep(i,0,8)
{
tmpx=x,tmpy=y,tmpInd=ind;
while(1)
{
if(tmpx>=m||tmpy>=n||tmpx<0||tmpy<0)
break;
if(ch[tmpx][tmpy]!=st[tmpInd])
break;
tmpInd++;
if(tmpInd==l)
return 1;
tmpx+=dx[i];
tmpy+=dy[i];
}
}
return 0;
}
int main()
{
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
int t,k,chk,ii;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
rep(i,0,m)
{
scanf("%s",ch[i]);
rep(j,0,n)
{
if(ch[i][j]>=65&&ch[i][j]<=90)
ch[i][j]+=32;
}
}
scanf("%d",&k);
while(k--)
{
scanf("%s",st);
l=strlen(st);
rep(i,0,l)
{
if(st[i]>=65&&st[i]<=90)
st[i]+=32;
}
rep(i,0,m)
{
rep(j,0,n)
{
if(ch[i][j]==st[0])
{
chk=valid(i,j,0);
if(chk)
{
printf("%d %d", i+1, j+1);
goto prnt;
}
}
}
}
prnt:
puts("");
}
if(t)
puts("");
}
return 0;
}