#include<iostream> #include<cstdio> #include<cctype> #include<cmath> #include<vector> #include<map> #include<utility> #include<algorithm> #define db(a) cout << #a << " = " << a << endl; #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl; #define foreach(it, l) for(typeof(l.begin()) it = l.begin(); it != l.end(); it++) using namespace std; char matriz[50][50]; int main() { int t, m, n, k; scanf("%d\n", &t); map> mapa; for(int r = 0; r < t; r++){ if(r != 0) printf("\n"); mapa.clear(); scanf("%d %d\n", &m, &n); for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { scanf("%c", &matriz[i][j]); matriz[i][j] = tolower(matriz[i][j]); } getchar(); } scanf("%d", &k); vector words(k); vector found(k, false); for (int i = 0; i < k; i++) { cin >> words[i]; transform(words[i].begin(), words[i].end(), words[i].begin(), ::tolower); } getchar(); //solution bool ok = false; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { for(int v = 0; v < k; v++){ if(found[v]) continue; int tam = words[v].size(); ok = false; for(int x = -1; x <= 1 && !ok; x++){ for(int y = -1; y <= 1 && !ok; y++){ if(x == 0 && y == 0 && tam != 1) continue; if(i + tam * x >= -1 && i + tam * x <= m) if(j + tam * y >= -1 && j + tam * y <= n){ ok = true; for(int s = 0; s < tam & ok; s++){ if(words[v][s] != matriz[i + s * x][j + s * y]) ok = false; } if(ok) found[v] = true; if(ok) mapa[words[v]].first = i + 1, mapa[words[v]].second = j + 1; } } } } } } for(int i = 0; i < words.size(); i++){ if(mapa[words[i]].first != 0) printf("%d %d\n", mapa[words[i]].first, mapa[words[i]].second); } } return 0; }
lunes, 24 de octubre de 2011
10010 - Where's Waldorf?, uva
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario