[Cpp]
/** The violence law is used here. First, all uppercase letters are converted to lowercase letters, and then the entire matrix is traversed,
* Search in 8 directions, obtain the searched string, and then match the target string
* Comparison: If the searched string contains the target string, the string is found and the output position is
*/
# Include <cstdio>
# Include <algorithm>
# Include <cstring>
# Include <iostream>
Using namespace std;
# Deprecision MAX 200
# Define DIR 8
Char map [MAX] [MAX];
Char street [MAX] [MAX];
Char all [MAX];
Int dir [] [2] = {0,-1}, {1,-1 },
{}, {-1,-1 }};
// Find each string
Char * findAll (int row, int col, int max_row, int max_col, int d ){
Int tmp_x, tmp_y, tmp_row, tmp_col, n (0 );
All [n ++] = map [row] [col];
Tmp_row = row; tmp_col = col;
Tmp_x = 0; tmp_y = 0;
Do {
Tmp_x + = dir [d] [0]; tmp_y + = dir [d] [1];
Tmp_row = row + tmp_x; tmp_col = col + tmp_y;
If (tmp_row> = 0 & tmp_row <max_row & tmp_col> = 0 & tmp_col <max_col)
All [n ++] = map [tmp_row] [tmp_col];
} While (tmp_row> = 0 & tmp_row <max_row & tmp_col> = 0 & tmp_col <max_col );
All [n] = '\ 0 ';
Return all;
}
// Compare whether the target string is a substring that finds the string
Int findstreet (const char * s, char * all ){
For (int I = 0; I <strlen (s); I ++ ){
If (s [I]! = All [I])
Return 0;
}
Return 1;
}
// Traverse each location
Void findPos (const char * s, int row, int col ){
For (int I = 0; I <row; I ++ ){
For (int j = 0; j <col; j ++ ){
For (int l = 0; l <DIR; l ++ ){
Char * all = findAll (I, j, row, col, l );
If (findstreet (s, all )){
Printf ("% d \ n", I + 1, j + 1 );
Return;
}
}
}
}
}
Int main (int argc, char const * argv [])
{
Int cas, row, col, ans_num;
Scanf ("% d", & cas );
While (cas --){
Scanf ("% d", & row, & col );
For (int I = 0; I <row; I ++ ){
Scanf ("% s", & map [I]);
For (int j = 0; j <strlen (map [I]); j ++)
If (isupper (map [I] [j]) map [I] [j] + = 32;
} Www.2cto.com
Scanf ("% d", & ans_num );
Getchar ();
For (int I = 0; I <ans_num; I ++ ){
Gets (street [I]);
For (int j = 0; j <strlen (street [I]); j ++)
If (isupper (street [I] [j]) street [I] [j] + = 32;
}
For (int I = 0; I <ans_num; I ++ ){
FindPos (street [I], row, col );
}
}
Return 0;
}