Word程序用于Word迷宫 [英] c program for Word Maze

查看:123
本文介绍了Word程序用于Word迷宫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多人会看到一个纸笔游戏,其中会出现一个字母表格。当第一次看到这个时,很可能只有一组看似随机的字母表。仔细观察,可以看出沿着特定的行和列有隐藏的有意义的单词。看看你是否能发现行和列中隐藏的单词。



RNIGHTLYIY

XITWQLZNOV

AGYBXMNUYL

QHNOTFVJKN

VTMIDOUYRI

PLBXGGKIFG

RYKFNHENOH

VJFDKTTCMT

HDXZWQNLTL

VBCOKHFTYY



需要编写一个完整的C程序,它将一个单词迷宫作为用户的输入,并且将其存储在适当的数据结构中。然后在迷宫中给用户一个要搜索的单词。程序必须在迷宫中沿水平和垂直方向找到所有出现的单词。



一旦在迷宫中找到单词的位置,程序也必须通过空格字符替换迷宫中不属于所定位单词的所有其他字符。程序必须显示迷宫,现在只有搜索到的单词的位置和出现。





给你一个枚举< br $>


typedef enum {

TOP = 0,

LEFT,

RIGHT,

BOTTOM,

}方向;

这个枚举代表不同的方向,顾名思义。方向表示如下:

TOP:从BOTTOM到TOP

LEFT:从右边向左边

右:从左边向右边

BOTTOM:从TOP到BOTTOM



你需要写2个函数:



1. void trimMaze(char迷宫[MAX_ORDER] [MAX_ORDER],int orderOfMaze,char word [])

此函数接收二维数组迷宫和orderOfMaze。迷宫中的行数和列数等于orderOfMaze。该函数还接收需要搜索的单词。您需要找到所有需要搜索的单词,并用迷宫中的空格字符替换所有其他字符,这些字符不是定位单词的一部分,并将结果存储回二维数组迷宫。 br />


例如:

迷宫是:



ratat

rsbca

aetar

tbcda

ratwz



需要搜索的单词是:老鼠。

然后修剪迷宫后会像:

ratt

ra

atar

t

rat



2. int getPositions(int positions [MAX_POSITIONS] [NUM_OF_ATTRIBUTES],int posLength,char word [], char迷宫[MAX_ORDER] [MAX_ORDER],int orderOfMaze,DIRECTION d,int r,int c)

此函数接收二维位置数组。在位置数组中,每行表示单词的位置,而列表示单词的索引和方向。在位置数组中,第一列表示单词的rowIndex,第二列表示单词的columnIndex,第三列表示找到单词的DIRECTION。

索引我们指的是单词''起始字母的数组索引。

示例:

如果单词ABC在数组中有索引:

A:row-0 col- 3

B:row-0 col- 4

C:row-0 col-5



然后在位置数组中第一行将有

0 3 RIGHT

注意方向是正确的,因为从LEFT向右搜索时找到了单词。



该函数还接收位置数组的长度,即posLength。当您找到单词的位置时,您必须将这些位置附加到数组位置,最后您必须返回位置数组的新长度。



函数还接收需要搜索的单词,你需要搜索单词的迷宫,迷宫的顺序,你必须搜索单词的方向。

该函数也接收行index r和column index c,表示必须从中开始搜索单词的行列索引。

示例:

如果传递的参数是

r = 1

c = 0

d = BOTTOM

迷宫的订单= 10

然后您搜索的索引是:

(1,0),(2,0), (3,0),(4,0),(5,0),(6,0),(7,0),(8,0),(9,0)

Many of you would have seen a paper-and-pencil game in which a table of alphabets is presented. When one looks at this for the first time, it is likely that only a seemingly random set of alphabets are present. On close look, one can discern that there are meaningful words "hidden" along particular rows and columns. See if you can discover the word NIGHTLY tucked away in rows and columns.

R N I G H T L Y I Y
X I T W Q L Z N O V
A G Y B X M N U Y L
Q H N O T F V J K N
V T M I D O U Y R I
P L B X G G K I F G
R Y K F N H E N O H
V J F D K T T C M T
H D X Z W Q N L T L
V B C O K H F T Y Y

It is required to write a complete C program that takes a word maze as input from the user, and store this in an appropriate data structure. Then the user is given a word to be searched in the maze. The program must locate all occurrences of this word in the maze along Horizontal and Vertical directions.

Once the locations of the word are found in the maze, the program must also replace all other characters in the maze which are not part of the located words, by the ''space'' character. The program must display the maze which now has only the locations and occurrences of the word searched for.


You are given an enum

typedef enum {
TOP = 0,
LEFT,
RIGHT,
BOTTOM,
} DIRECTION;
This enum represents different directions as the names suggests. The direction representation is as following:
TOP : from BOTTOM towards TOP
LEFT : from RIGHT towards LEFT
RIGHT : from LEFT towards RIGHT
BOTTOM : from TOP towards BOTTOM

You are required to write 2 functions:

1. void trimMaze(char maze[MAX_ORDER][MAX_ORDER], int orderOfMaze, char word[])
This function receives a two dimensional array maze and the orderOfMaze. Number of rows and columns in the maze are equal to the orderOfMaze. The function also receives the word which needs to be searched. You are required to locate all occurrences of the word that needs to be searched and replace all other characters with ''space'' characters in the maze which are not part of the located words and store the result back in two dimensional array maze.

Example:
the maze is:

r a t a t
r s b c a
a e t a r
t b c d a
r a t w z

the word that needs to be searched is: "rat".
then after trim maze will be like:
r a t t
r a
a t a r
t
r a t

2. int getPositions(int positions[MAX_POSITIONS][NUM_OF_ATTRIBUTES], int posLength, char word[], char maze[MAX_ORDER][MAX_ORDER], int orderOfMaze, DIRECTION d, int r, int c)
This function receives a two dimensional positions array. In positions array every row represents a position of the word whereas columns represent the Indexes and directions of the word. In positions array first column represents the rowIndex of the word, second column represents the columnIndex of the word and third column represents DIRECTION in which word was found.
By Index we mean the array index of the word''s starting letter.
Example:
If word ABC has indexes in array:
A: row- 0 col- 3
B: row- 0 col- 4
C: row- 0 col- 5

Then in positions array the first row will have
0 3 RIGHT
Note that the direction is RIGHT because the word was found while searching from LEFT towards RIGHT.

The function also receives length of the positions array which is posLength. As you find positions of the word you have to append those positions to the array positions and at the end you have to return the new length of the positions array.

The function also receives the word which needs to be searched, the maze in which you need to search the word, order of the maze, direction towards which you have to search the word.
The function also receives row index r and column index c which represents the row column indexes from which you have to start searching the word.
Example:
If parameters passed are
r = 1
c = 0
d = BOTTOM
order of maze = 10
then indexes you will search are:
(1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0),(9,0)

推荐答案

做好自己的作业:这是一种非常有效的学习方式。

请阅读常见问题解答。
Do yourself your own homework: it is a pretty effective way of learning.
And, please, read the FAQ.


只是在这里发布你的家庭作业并不会让别人为你做这件事。检查您的课堂笔记和课本,并尝试为自己做点什么。你会从中学到更多东西。
Just posting your homework assignment here is not going to get someone to do it for you. Review your class notes and textbook and try to do something for yourself. You will learn a lot more that way.


这篇关于Word程序用于Word迷宫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆