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
3924 - Cripto 1
(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 decrypt_text(language, encrypted_text, permutation): decrypted_text = [] for word in encrypted_text: decrypted_word = "" for i in range(len(word)): decrypted_word += language[word[i] - 1] decrypted_text.append(decrypted_word) decrypted_text_permuted = [] for word in decrypted_text: permuted_word = "" for i in range(len(word)): permuted_word += word[permutation[i] - 1] decrypted_text_permuted.append(permuted_word) return decrypted_text_permuted def similarity(language, decrypted_text): count = 0 for word in decrypted_text: if word in language: count += 1 return count def read_input(file_name): with open(file_name, 'r') as file: N, M, K, Q = map(int, file.readline().split()) language = file.readline().split() encrypted_text = [file.readline().split()[0] for _ in range(M)] permutations = [list(map(int, file.readline().split())) for _ in range(Q)] return N, M, K, Q, language, encrypted_text, permutations def write_output(file_name, result): with open(file_name, 'w') as file: file.write(str(result[0]) + ' ' + str(result[1])) def find_best_decryption(N, M, K, Q, language, encrypted_text, permutations): max_similarity = -1 best_permutation_index = -1 for i in range(Q): decrypted_text = decrypt_text(language, encrypted_text, permutations[i]) current_similarity = similarity(language, decrypted_text) if current_similarity > max_similarity: max_similarity = current_similarity best_permutation_index = i + 1 return best_permutation_index, max_similarity def main(): N, M, K, Q, language, encrypted_text, permutations = read_input("cripto1.in") result = find_best_decryption(N, M, K, Q, language, encrypted_text, permutations) write_output("cripto1.out", result) 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