Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1829 - Cuvinte Ascunse
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Rezolvare == <syntaxhighlight lang="python" line> def is_valid_cell(i, j, n, m): return 0 <= i < n and 0 <= j < m def search_word(grid, word, n, m, visited, i, j, idx): if idx == len(word): return True if not is_valid_cell(i, j, n, m) or visited[i][j] or grid[i][j] != word[idx]: return False visited[i][j] = True for di in [-1, 0, 1]: for dj in [-1, 0, 1]: if (di, dj) != (0, 0) and search_word(grid, word, n, m, visited, i + di, j + dj, idx + 1): return True visited[i][j] = False return False def count_word_occurrences(grid, word, n, m): count = 0 for i in range(n): for j in range(m): if grid[i][j] == word[0]: visited = [[False] * m for _ in range(n)] if search_word(grid, word, n, m, visited, i, j, 0): count += 1 return count def main(): with open("cuvinteascunse.in", "r") as fin: n, m, c = map(int, fin.readline().split()) grid = [fin.readline().split() for _ in range(n)] words = [fin.readline().strip() for _ in range(c)] word_counts = {} for word in words: count = count_word_occurrences(grid, word, n, m) if count > 0: word_counts[word] = count sorted_words = sorted(word_counts.items(), key=lambda x: x[1], reverse=True) with open("cuvinteascunse.out", "w") as fout: fout.write(str(len(sorted_words)) + "\n") for word, count in sorted_words: fout.write(f"{word} {count}\n") password = "" for i in range(n): for j in range(m): if grid[i][j] != "?": password += chr(ord("a") + (count_word_occurrences(grid, grid[i][j], n, m) % 26)) fout.write(password + "\n") if __name__ == "__main__": main() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width