单词搜索网格【难度:3级】:
#Word Search
创建一个程序来解决单词搜索难题。
在单词搜索谜题中你得到一个字母的方格,必须找到具体的
他们的话。
例如:
jefblpepre
camdcimgtc
oivokprjsm
pbwasqroua
rixilelhrs
wolcqlirpc
screeaumgr
alxhpburyi
jalaycalmp
clojurermt
上面的方块中隐藏了几种编程语言。
单词可以隐藏在各种方向:从左到右,从右到左,垂直和对角线。
创建一个给出拼图和单词列表的程序返回每个单词的第一个和最后一个字母的位置。
您将获得一个Point(x,y)类,它将用于显示找到的单词的第一个和最后一个单词的点。
您将需要创建一个类WordSearch的方法search
,它接受参数word
并在提供的网格中搜索该单词。如果找到,它必须返回单词的第一个和最后一个字母的点,否则返回None。
例如,
puzzle =('jefblpepre \ n'
'camdcimgtc \ N'
'oivokprjsm \ N'
'pbwasqroua \ N'
'rixilelhrs的\ n'
'wolcqlirpc \ N'
'screeaumgr \ N'
'alxhpburyi \ N'
'jalaycalmp \ N'
'clojurermt')
>>> example = WordSearch(拼图)
>>> example.search('clojure')
(点(0,9),点(6,9))
从上面的“clojure”这个词来看,** c 可以在0,9点找到
最后一个字母 e **可以在第6,9点找到
注意:索引从0开始计数。
英文原题:
Word Search
Create a program to solve a word search puzzle.
In word search puzzles you get a square of letters and have to find specific
words in them.
For example:
jefblpepre
camdcimgtc
oivokprjsm
pbwasqroua
rixilelhrs
wolcqlirpc
screeaumgr
alxhpburyi
jalaycalmp
clojurermt
There are several programming languages hidden in the above square.
Words can be hidden in all kinds of directions: left-to-right, right-to-left, vertical and diagonal.
Create a program that given a puzzle and a list of words returns the location of the first and last letter of each word.
You will be provided with a Point(x, y) class which will be used to display the points of the first and last words of the found words.
You will be required to create a method search
of class WordSearch that takes in a parameter word
and searches through the provided grid for this word. It must return the Points of thw first and last letter of the word if found else return None.
An e.g.
puzzle = ('jefblpepre\n'
'camdcimgtc\n'
'oivokprjsm\n'
'pbwasqroua\n'
'rixilelhrs\n'
'wolcqlirpc\n'
'screeaumgr\n'
'alxhpburyi\n'
'jalaycalmp\n'
'clojurermt')
>>> example = WordSearch(puzzle)
>>> example.search('clojure')
(Point(0, 9), Point(6, 9))
From the above, from the word clojure
, c can be found at point 0,9
and the last letter e can be found at poin 6, 9
Note: indexes start counting from 0.
最佳答案合集(多种解法):
更多关联题目:
降序排列【难度:1级】–景越Python编程训练之挑战1000道Python面试题(含答案)
简单的乐趣#31:替换密码?【难度:2级】–景越Python编程训练之挑战1000道Python面试题(含答案)
Krazy King二十一点【难度:3级】–景越Python编程训练之挑战1000道Python面试题(含答案)
免责申明:
本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢