`
jackchen0227
  • 浏览: 142706 次
  • 性别: Icon_minigender_1
  • 来自: 帝都
社区版块
存档分类
最新评论

joj 1014 the matrix 从八个方向遍历访问矩阵

    博客分类:
  • ACM
阅读更多

 

 1014: The Matrix


Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
3s 8192K 2109 670 Standard

Given a matrix of characters, and a list of words, output whether or not each word is present in the matrix. Words may appear forwards and backwards. They may appear horizontally, vertically, and diagonally.

Input


The matrix, followed by a list of words. Only lower case characters will be used. Each matrix will be square, and contain no more than 20 characters on a side. The string XXX denotes the end of input.

Output


For each word, report whether or not it is present in the matrix. If it is present, output should read “<word> is in the matrix.” If it is not present, output should read “<word> is not in the matrix.”, where <word> is the word in question.

Sample Input

applexy
pxlhjke
edeqgfl
xocgvpl
gghnmnn
tahuupu
qdgbywb
apple
axe
apex
cat
car
hat
computer
gum
XXX

Sample Output

apple is in the matrix.
axe is in the matrix.
apex is in the matrix.
cat is not in the matrix.
car is not in the matrix.
hat is in the matrix.
computer is not in the matrix.
gum is in the matrix.

 

/*
	水题一个
	关键是找字符的时候
	沿着八个方向找
	但是每一次只能沿着一个方向遍历下去
*/
#include <stdio.h>
#include <string.h>
char matrix[21][21];
char str[21];
bool isIn(int row,int col)
{
	char tmp[21];
	memset(tmp,'\0',sizeof(tmp));
	tmp[0] = str[0];
	int var[2][8] = {{0,0,-1,1,1,-1,1,-1},
					{1,-1,0,0,-1,1,1,-1}};
	int curRow = 0,curCol = 0;
	for(int i=0;i<8;i++) //一共有八个方向
	{
		curRow = row;
		curCol = col;
		for(int j=1;j<strlen(str);j++) //一次只能沿着一个方向找
		{
			curRow += var[0][i];
			curCol += var[1][i];
			tmp[j] = matrix[curRow][curCol];
		}
		if(strcmp(tmp,str) == 0)
			return true;
	}
	return false;
}
int main()
{
	memset(matrix,'\0',sizeof(matrix));
	freopen("in.txt","r",stdin);
	scanf("%s",matrix[0]);
	for(int k=1;k<strlen(matrix[0]);k++)
		scanf("%s",matrix[k]);
	while(scanf("%s",str),strcmp(str,"XXX"))
	{
		bool flag = false;
		for(int i=0;i<strlen(matrix[0]);i++)
		{
			for(int j=0;j<strlen(matrix[0]);j++)
				if(matrix[i][j] == str[0])
					if(isIn(i,j))
					{
						flag = true;
						break;
					}
			if(flag)
				break;
		}
		if(flag)
			printf("%s is in the matrix.\n",str);
		else
			printf("%s is not in the matrix.\n",str);
	}
	fclose(stdin);
	return 0;
}
分享到:
评论

相关推荐

    joj 部分题目答案 自己做的 仅供参考

    joj 部分题目答案 自己做的 仅供参考 joj 部分题目答案 自己做的 仅供参考 joj 部分题目答案 自己做的 仅供参考 joj 部分题目答案 自己做的 仅供参考 joj 部分题目答案 自己做的 仅供参考

    joj上做的一些ACM试题

    在JOJ上做的一些ACM试题,都通过在线测试。

    joj.rar_joj

    本程序能实现操作系统中的先进先出页面置换算法

    joj acm 部分习题解答

    一些题目解答 1001-1012 自己做的,希望能帮助到一些朋友

    JOJ-jilin-university--acm.rar_joj

    可以为在JOJ上练习的同学做入门使用,这些代码全部通过。

    acm.rar_acm jlu 10_acm jlu 1029_joj 1237_joj10

    joj acm 源代码,即一些题得答案,方便大家联系参考。加油吧。

    JoJ-crx插件

    Etre au courant quand JoJ est en live,策划人semaine et liens vers lesréséauxauxsocioaux Soyez au courant纠结JoJ开始à流光! 现场直播将继续进行。 约翰·奎因·伊斯特·布鲁和克林·德集团的非官方网站 D...

    一个有关调度的问题joj1015

    这个题其实现在想起来也不知道是怎么就给ac的。

    吉林大学 joj 1000-2645题代码

    吉林大学 joj 1000-2645题代码,嘿嘿,大家就不用在花JPOINT买代码了,祝ACMer实现自己的心愿

    Joj - Java Version of Java-开源

    Joj 以与 JDOM 提供 XML 的 Java 表示类似的方式提供 Java 源代码的 Java 对象表示。

    joj 1424 硬币兑换问题

    硬币转化问题。用动态规划解决,不是很难。

    吉林大学ACM题集.pdf-JOJ

    整理的ACM题集,吉林大学的,pdf格式,jilin univercity online judge system

    acm joj 1600

    关于大数取模的运算,比如说:a^b%m。下面提供2种解法。

    jovo-plugins:J Jovo框架插件

    插入 由 Jovo插件自动将有关传入Alexa CanFulfillRequests的数据发送到Slack Webhook 由 Jovo插件以电子邮件发送错误 由 一个Jovo插件可以自动将错误消息发送到Slack Webhook 由KaanKC Jovo插件可自动将来自传入的...

    JoJo-s-Bizarre-Survival:一个模组,将JoJo的奇异冒险中的看台添加到Minecraft

    这个mod的目的是要从专营权中尽可能多地增加Minecraft,该mod目前仅包含Stand能力,其他能力(Hamon,Vampirism)将在以后的更新中添加。 如果您不将行为视为不同的立场(如果您这样做的话,则为31个),该模块中...

    furystudios

    furystudios 普尔维·扎达塔克(Prvi zadatak) ...DroppingOff - radnikhodajućidolazi做pripadajuće科萨雷(izvedeno kroz provjeru tagova kutije)我卡达joj JE dovoljno blizu,fizičkiJE lan

    ControlEstoque_GH:..

    Este Projeto签证是由estoque进行的,它是由mer mercadorias uma determinada empresa sejam averiguadas和atualizadas ... 2021年1月20日,由JoséCláudiodeAraújoJúnior和Annielly Ferreira de Sousa所设计。

    大智慧最新安装

    大智慧最新安装包,老的已经过期不能查询个人自选股,所以推荐最新的大智慧给大家安装

Global site tag (gtag.js) - Google Analytics