UVA - 10010 Where's Waldorf?
来源:互联网 发布:linux下删除用户 编辑:程序博客网 时间:2024/05/22 13:54
题目大意:给出几行几列的字母和几个单词,从字母列表里找单词,单词要位于一条直线上,可以从八个方向求找,输出第一个单词在表中的位置,无视大小写。
解题思路:输入时全部化为小写字母,找到第一个相同字母的位置先记录,然后按方向检索,成功就输出。
#include<iostream> #include<cstdio>#include<string.h>#include<stdlib.h>#include<cmath>using namespace std;char map[100][100];char word[50];int xx[]={0,-1,-1,-1,0,1,1,1};int yy[]={-1,-1,0,1,1,1,0,-1};int main() { int T, m, n, N; scanf("%d", &T); while(T--) { memset (map, '\0', sizeof(map)); scanf("%d%d\n", &m, &n); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { scanf("%c", &map[i][j]); if (map[i][j] >= 'A' && map[i][j] <= 'Z') map[i][j] = map[i][j] - 'A' + 'a'; } getchar(); } scanf("%d\n", &N); while(N--) { memset (word, '\0', sizeof(word)); int x = 0, y = 0, k = 0; gets(word); int len = strlen(word); for (int i = 0; i < len; i++) { if (word[i] >= 'A' && word[i] <= 'Z') word[i] = word[i] - 'A' + 'a'; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if(map[i][j] == word[0]) for (int t = 0; t < 8; t++) { x = i; y = j; for (k = 0; x >= 0 && x <= m && y >= 0 && y <= n; k++) { if (map[x][y] != word[k]) break; if (k == len - 1) printf("%d %d\n", i+1, j+1); x += xx[t]; y += yy[t]; } if (k == len) break; } if (k == len) break; } if (k == len) break; } } if(T) printf("\n"); } return 0; }
1 0
- 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?
- UVA - 10010 - Where's Waldorf
- Android TextView文字中底部或者中间加横线
- C语言实现二叉树
- arm9 mini2440 supervivi烧写方法
- 5个强大的Java分布式缓存框架推荐
- 关于变量和函数的初始化和执行次序
- UVA - 10010 Where's Waldorf?
- JAVA的基本数据类型和引用数据类型的区别
- UVA - 10879 Code Refactoring
- Java中List和ArrayList的区别
- JAVA: List用法
- java整型byte,short,int,long取值范围大小
- sql server 与 mysql在自定以数据类型的区别
- UVA - 10250 The Other Two Trees
- 线程同步引发的安全问题