Похожие чаты

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

18 просмотров

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

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

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

Какой-то там пердун в 90-х решил, что есть какая-то разная типизация. Кого вообще это волнует?
КТ315
49
Hi. Do we have a raid bot? Why nobody doing raids on X? Even RH mentioned this and nobody paying attention...whats the channel for hex memes? If mods cant run raids just insta...
H
31
Подскажите, а есть vault lite или ченить такое?) А то нужен вольт для похода в вольт, но весит он ~500 мб) как-то многовато для парочки запросов ))
Alexandr Orloff
17
блеать, почему так?? где в роутере это исправляется?
Арсен Маньяков 🇦🇲
16
void terminal_scroll() { memmove(terminal_buffer, terminal_buffer + VGA_WIDTH, buffer_size - VGA_WIDTH); memset(terminal_buffer + buffer_size - VGA_WIDTH, 0, VGA_WIDTH); ...
Егор
47
🌊 Ocean Nodes Dashboard Update 🚀 Hey, Oceaners! First off, a massive round of applause 👏to all of you for the amazing engagement since we launched Ocean Nodes. In just a few ...
KreigDK | Never DM first🌊
3
Всем привет! Подскажите, пожалуйста, в чем ошибка? Настраиваю подключение к MySQL. Либы лежат рядом с exe. Все как по "учебнику"
Евгений
16
А можете как-то проверить меня по знаниям по ассемблеру?
A A
132
Здравствуйте! У меня появилась возможность купить книгу "Изучай Haskell во имя добра!". Но я где-то слышал, что эта книга устарела. Насколько это правда??
E
22
люди, которые используют flameshot, к вам вопрос. Можно-ли поставить хоткей на создание скриншота? В программе есть отдел "горячие клавиши", но там все для редактирования, скр...
ThunDer104
11
Карта сайта