ACM-uva10010
2013-10-20 19:31
363 查看
#include <iostream> #include <string> #include <string.h> using namespace std; #define MAXN 50 + 5 int temp[MAXN][MAXN]; int r, c; int dir[8][2] = { 0, -1, -1, 0, 0, 1, 1, 0, -1, -1, -1, 1, 1, 1, 1, -1 }; int ansr, ansc; int change(char ch) { if (ch >= 'a' && ch <= 'z') { return ch - 'a'; } else { return ch - 'A'; } } bool match(int x, int y, string &str) { int len = str.length(); int num = 0; for (int i = 0; i < 8; i++) { num = 0; for (int j = 0; j < len; j++) { int xt = x + j * dir[i][0], yt = y + j * dir[i][1]; if (xt >= 0 && xt < r && yt >= 0 && yt < c) { if (temp[xt][yt] == change(str[j])) { num++; } else { break; } } else { break; } } if (num == len) { return true; } } return false; } void find(string &str) { bool ok = false; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (temp[i][j] == change(str[0])) { if (match(i, j, str)) { ansr = i + 1; ansc = j + 1; ok = true; break; } } } if (ok) { break; } } } void input() { int t, k; string str; char ch; cin >> t; while (t--) { cin >> r >> c; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { cin >> ch; temp[i][j] = change(ch); } } cin >> k; for (int i = 0; i < k; i++) { cin >> str; find(str); cout << ansr << ' ' << ansc << endl; } if (t) { cout << endl; } } } int main() { input(); return 0; }
相关文章推荐
- acm-uva10653解题报告
- acm-UVA247解题报告
- UVA - 10600 ACM Contest and Blackout
- UVa 10010
- UVA - 10112 Myacm Triangles
- Score, ACM/ICPC Seoul 2005, UVa 1585
- UVA 10600 ACM Contest and Blackout(最小生成树and次小生成树)
- UVA 10600 ACM Contest and Blackout(次小树,3级)
- [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]
- uva——10010
- acm-UVA1055(水题)
- UVa 10600 - ACM Contest and Blackout
- ACM: uva 11210 &n…
- Abbott 的复仇(Abbott's Revenge,ACM|IPPC World Finals 2000, UVa 816)
- ACM: uva 1276 - Network
- ACM: uva 11584 -
- [ACM_动态规划] UVA 12511 Virus [最长公共递增子序列 LCIS 动态规划]
- ACM UVa 算法题 #110 - Meta-Loopless Sort 的解法
- [Score, ACM/ICPC Seoul 2005, UVA1585]
- ACM 计算器 类似24点 UVALive 6163 Myth Busters