UVA 10010 (暑假-字符串(2) -A - Where's Waldorf?)
2014-07-08 21:05
337 查看
#include <stdio.h> #include <string.h> #define MAX 21 #define MAX2 51 int main() { int t; scanf("%d", &t); while (t--) { //输入数据 char str[MAX2][MAX2], str2[MAX][MAX2]; int m, n; scanf("%d%d", &m, &n); getchar(); for (int i = 0; i < m; i++) gets(str[i]); int k; scanf("%d", &k); getchar(); for (int i = 0; i < k; i++) gets(str2[i]); // 把所有字母转换成小写 for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) if ( str[i][j] < 97 ) str[i][j] += 32; for (int i = 0; i < k; i++) { int len = strlen(str2[i]); for (int j = 0; j < len; j++) if (str2[i][j] < 97) str2[i][j] += 32; } //从字母表中寻找单词 for (int r = 0; r < k; r++ ) { //从第一个单词开始 int len = strlen(str2[r]), kong = 0; for (int i = 0; i < m && kong == 0; i++) for (int j = 0; j < n && kong == 0; j++) { //单词的字母和字母表的字母匹配 int s2 = 0, x = i, y = j; while (j < n && str2[r][s2++] == str[i][j++] && kong == 0) { //向右匹配 if (s2 == len) kong = 1; } s2 = 0,i = x, j = y; while (j >= 0 && str2[r][s2++] == str[i][j--] && kong == 0) { //向左匹配 if (s2 == len) kong = 1; } s2 = 0, i = x, j = y; while (i < m && str2[r][s2++] == str[i++][j] && kong == 0) {//向上匹配 if (s2 == len) kong = 1; } s2 = 0,i = x, j = y; while ( i >= 0 && str2[r][s2++] == str[i--][j] && kong == 0) {//向下匹配 if (s2 == len) kong = 1; } s2 = 0,i = x, j = y; while ( i < m && j < n && str2[r][s2++] == str[i++][j++] && kong == 0) {//向右上匹配 if (s2 == len) kong = 1; } s2 = 0, i = x, j = y; while ( i < m && j>= 0 &&str2[r][s2++] == str[i++][j--] && kong == 0) {//向右下匹配 if (s2 == len) kong = 1; } s2 = 0,i = x, j =y; while ( i >= 0 && j >= 0 &&str2[r][s2++] == str[i--][j--] && kong == 0) {//向左下匹配 if (s2 == len) kong = 1; } s2 = 0,i = x, j = y; while ( i >= 0 && j < n && str2[r][s2++] == str[i--][j++] && kong == 0) {//向左上匹配 if (s2 == len) kong = 1; } s2 = 0, i = x, j =y; if (kong == 1) { //如果匹配成功就输出 printf("%d %d\n", x + 1, y + 1); break; } } } if (t) printf("\n"); } return 0; }
相关文章推荐
- uva 10010 Where's Waldorf?(DFS字符串查找)
- UVa Problem 10010 Where’s Waldorf?(寻找单词)
- UVA - 10010 - Where's Waldorf
- UVA 10010-- Where's Waldorf?
- UVA 10010 Where's Waldorf?
- UVa10010 Where's Waldorf?
- uva 10010 Where's Waldorf?(字符串处理)
- uva 10010 Where's Waldorf?
- UVA 10010 Where's Waldorf?
- UVa 10010 - Where's Waldorf?
- uva10010 - Where's Waldorf?
- 字符串-10010 Where’s Waldorf
- UVA 10010 - Where's Waldorf?
- UVa 10010: Where's Waldorf?
- UVA - 10010 Where's Waldorf?
- UVa 10010 - Where's Waldorf?
- UVA10010 Where's Waldorf?
- UVA 10010- Where's Waldorf?(八方向寻找字符串)
- UVa - 10010 - Where's Waldorf?
- uva-10010 - Where's Waldorf?