Похожие чаты

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 ответов

29 просмотров

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

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

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

30500 за редактор? )
Владимир
47
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Anyone else having this error when trying to make transactions?
Datzel
11
Question: How viable is it to use Anvil as the backend infrastructure for managing a TradFi portfolio, while integrating Flexa for instant liquidity and payment solutions? Cou...
Kevin
2
вы делали что-то подобное и как? может есть либы готовые? увидел картинку нокода, где всё линиями соединено и стало интересно попробовать то же в ddl на lua сделать. решил с ч...
Victor
8
Карта сайта