UVA 10010 (暑假-字符串(2) -A - Where's Waldorf?)
来源:互联网 发布:淘宝网男装新款 编辑:程序博客网 时间:2024/05/01 07:23
#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;}
0 0
- UVA 10010 (暑假-字符串(2) -A - Where's Waldorf?)
- UVA 10010 - Where's Waldorf?(字符串)
- UVa 10010 - Where's Waldorf?
- uva 10010 Where's Waldorf?
- UVa 10010 - Where's Waldorf?
- UVa 10010 - Where's Waldorf?
- uva-10010 - Where's Waldorf?
- UVA 10010 - Where's Waldorf?
- UVa 10010 - Where's Waldorf?
- UVa 10010 - Where's Waldorf?
- UVA 10010 Where's Waldorf?
- UVa 10010: Where's Waldorf?
- UVA 10010 Where's Waldorf?
- UVa - 10010 - Where's Waldorf?
- UVA 10010 Where's Waldorf?
- uva 10010 - Where's Waldorf?
- uva 10010 Where's Waldorf?
- uva - 10010 - Where's Waldorf?
- 使用CoreText实现的一个富文本显示组件
- jsp、el、jstl——前端面试
- java8 - 方法引用(method referrance)
- HDU2955概率背包
- 华为测试 超长整数相加
- UVA 10010 (暑假-字符串(2) -A - Where's Waldorf?)
- C语言里面的内联函数(inline)与宏定义(#define)探讨
- java学习笔记——java中对象的创建,初始化,引用的解析
- C++学习笔记32 谓词函数
- C 判断某年某月某日是本年度的第几天
- 链接mysql数据库出现Unknown character set: 'utf8mb4'问题
- UVA 409 (暑假-字符串(2) -B - Excuses, Excuses!)
- UVA 10878 (暑假-字符串(2) -C - Decode the tape)
- 冒泡排序以及一些基本格式