- 1、本文档共8页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
2016届华为公司校园招聘华为软件开发工程师提前批上机笔试题
Word?Maze?是一个网络小游戏,你需要找到以字母标注的食物,但要求以给定单词字母的顺序吃掉。如上图,假设给定单词if,你必须先吃掉i然后才能吃掉f。????但现在你的任务可没有这么简单,你现在处于一个迷宫Maze(n×m的矩阵)当中,里面到处都是以字母标注的食物,但你只能吃掉能连成给定单词W的食物。如下图,指定W为“SOLO”,则在地图中红色标注了单词“SOLO”。??注意区分英文字母大小写,你只能上下左右行走。运行时间限制:无限制内存限制:无限制输入:输入第一行包含两个整数n、m(0n,?m21)分别表示n行m列的矩阵,第二行是长度不超过100的单词W,从第3行到底n+3行是只包含大小写英文字母的长度为m的字符串。输出:如果能在地图中连成给定的单词,则输出“YES”,否则输出“NO”。注意:每个字母只能用一次。样例输入:5 5SOLOCPUCYEKLQHCRSOLEKLQOPGRBC样例输出:YES答案提示:bool maze(char array[21][21], int m, int n, char *word){inti, j, w=0;int x, y;for (i=0; im; i++){x = i;for (j=0; jn; j++){y = j;if (array[x][y] == word[w]){while (\0 != word[w]){w++;if ((x0) (xm-1) (y0) (yn-1)){if (array[x-1][y] == word[w]){x = x-1;}else if (array[x+1][y] == word[w]){x = x+1;}else if (array[x][y-1] == word[w]){y = y-1;}else if (array[x][y+1] == word[w]){y = y+1;}elsebreak;} else if ((xm-1) (y0) (yn-1)){if (array[x+1][y] == word[w]){x = x+1;}else if (array[x][y-1] == word[w]){y = y-1;}else if (array[x][y+1] == word[w]){y = y+1;}elsebreak;}else if ((x0) (y0) (yn-1)){if (array[x-1][y] == word[w]){x = x-1;}else if (array[x][y-1] == word[w]){y = y-1;}else if (array[x][y+1] == word[w]){y = y+1;}elsebreak;}else if ((x0) (xm-1) (yn-1)){if (array[x-1][y] == word[w]){x = x-1;}else if (array[x+1][y] == word[w]){x = x+1;}else if (array[x][y+1] == word[w]){y = y+1;}elsebreak;}else if ((x0) (xm-1) (y0)){if (array[x-1][y] == word[w]){x = x-1;}else if (array[x+1][y] == word[w]){x = x+1;}else if (array[x][y-1] == word[w]){y = y-1;}elsebreak;}else if ((xm-1) (yn-1)){if (array[x+1][y] == word[w]){x = x+1;}else if (array[x][y+1] == word[w]){y = y+1;}elsebreak;}else if ((xm-1) (y0)){if (array[x+1][y] == word[w]){x = x+1;}else if (array[x][y-1] == word[w]){y = y-1;}elsebreak;}else if ((x0) (yn-1)){if (array[x-1][y] == word[w]){x = x-1;}else if (array[x][y+1] == word[w]){y = y+1;}elsebreak;}else if ((x0) (y0)){if (array[x-1][y] == word[w]){x = x-1;}else if (array[x][y-1] == word[w]){y = y-1;}elsebreak;}}if (\0 == word[w]){return 1;}}}}return 0;}int ma
文档评论(0)