字符串-10010 Where’s Waldorf
来源:互联网 发布:阿里云视频直播服务器 编辑:程序博客网 时间:2024/05/21 19:24
题目大意:给定m*n的字母网格,给出需要找到的单词,按照八个方向分别查找,但是与普通的广搜或者深搜区别,方向始终保持一致,不弯曲,不交叉,找出最上最左的第一个字母位置
解题过程:一次AC,但是在调试过程中费了一点功夫,因为对scanf和printf还不熟,scanf按地址传递,printf直接打印
正确代码:
# include <cstdio># include <cstring># include <ctype.h># include <string># include <iostream>//# define LOCALusing namespace std;char grid[60][60];int dir[8][2]={{-1,-1},{-1,0},{-1,1,},{0,-1},{0,1},{1,-1},{1,0},{1,1}};int main(){# ifdef LOCALfreopen("in.txt","r",stdin);freopen("out.txt","w",stdout);#endifint a,n,m,k,j;scanf("%d",&a);//printf("%d\n",a);while(a){a--;scanf("%d%d",&m,&n);//printf("%d %d\n",m,n);char temp[n+1]; for(int i=0;i<m;i++){scanf("%s",temp);for(int j=0;j<n;j++){grid[i][j]=temp[j];//printf("%c",grid[i][j]);}//printf("\n"); }scanf("%d",&k);//printf("%d\n",k);char (* word)[60]=new char[k][60];for(int i=0;i<k;i++){scanf("%s",word[i]);//printf("%s\n",word[i]);}int numofword=0;while(numofword<k){int len=strlen(word[numofword]);int row=0,col=0;int pos=0;while(pos<len){for(int i=0;i<8;i++){if(row+dir[i][0]*(len-1)>=m||row+dir[i][0]*(len-1)<0||col+dir[i][1]*(len-1)>=n||col+dir[i][1]*(len-1)<0)continue;for(j=0;j<len;j++){if(grid[row+dir[i][0]*j][col+dir[i][1]*j]==toupper(word[numofword][j])||grid[row+dir[i][0]*j][col+dir[i][1]*j]==tolower(word[numofword][j]))continue;break;}if(j==len){pos=len;break;}}if(pos!=len){row+=(col+1)/n;col=(col+1)%n;}}printf("%d %d\n",row+1,col+1);numofword++;}if(a>0)printf("\n");}}
0 0
- 字符串-10010 Where’s Waldorf
- UVA 10010 - Where's Waldorf?(字符串)
- 10010- Where's Waldorf?
- 10010 Where's Waldorf?
- 10010 - Where's Waldorf?
- 10010 - Where's Waldorf?
- 10010 - Where's Waldorf?
- 10010 - Where's Waldorf?
- 10010 - Where's Waldorf?
- 10010 - Where's Waldorf?
- 10010 - Where's Waldorf?
- 10010 - Where's Waldorf?
- 10010 - Where's Waldorf?
- 10010 - Where's Waldorf?
- 字符串B Where's Waldorf?
- UVa 10010 - Where's Waldorf?
- uva 10010 Where's Waldorf?
- UvaOJ 10010 - Where's Waldorf?
- Swift基础(十)协议的委托代理
- 机器学习实战2:关联规则:议会投票+毒蘑菇
- [hihoCoder太阁最新面经算法竞赛8]B.Dice Possibility
- Android Service
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
- 字符串-10010 Where’s Waldorf
- 最值求解,活动安排,部分背包问题
- C++的简单总结(复制构造函数,深拷贝,前拷贝,默认属性)
- ViewPager + Fragment 实现类微信界面
- 机器学习实战3:逻辑logistic回归:病马实例
- 基数(cardinality)排序算法
- Part3:关联容器(一)
- 悟空传有感
- JS HTML转义码解码