Похожие чаты

I already tried with a solution like this, but it

seems not found anyone know how to do it ?
#!/bin/python3
import mathimport os
import randomimport re
import sys
## Complete the 'search_words' function below.
## The function is expected to return a STRING_ARRAY.
# The function accepts following parameters:# 1. STRING_ARRAY letters
# 2. STRING_ARRAY words#
def search_words(letters, words):
rows = len(letters) cols = len(letters[0])
def search(i, j, word, di, dj):
for k in range(len(word)): ni, nj = i + di*k, j + dj*k
if not (0 <= ni < rows and 0 <= nj < cols and letters[ni][nj] == word[k]): return False
return True
# Define the directions: horizontal right, vertical down, diagonal right-down, diagonal right-up directions = [
(0, 1), # horizontal right (1, 0), # vertical down
(1, 1), # diagonal right-down (-1, 1) # diagonal right-up
]
result = [] for word in words:
found = False for i in range(rows):
for j in range(cols): if letters[i][j] == word[0]:
for di, dj in directions: if search(i, j, word, di, dj):
found = True break
if found: break
if found: break
result.append("YES" if found else "NO") return result

if name == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
B = int(first_multiple_input[0])
K = int(first_multiple_input[1])
letters = []
for _ in range(B):
letters_item = input() letters.append(letters_item)
T = int(input().strip())
words = []
for _ in range(T):
words_item = input() words.append(words_item)
result = search_words(letters, words)
fptr.write('\n'.join(result))
fptr.write('\n')
fptr.close()

1 ответов

34 просмотра

send this as .py we cant read it in chat ✨

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта