Add 06/05

This commit is contained in:
augustin64 2024-05-06 15:22:19 +02:00
parent edcf3d3bc7
commit e9a50043d5
2 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,48 @@
import sys
from munkres import Munkres
m = Munkres()
n, k = map(int, input().split())
ciphering = input()
sol = input()
def from_letter(a):
if ord(a) < ord('a'):
return 26+ord(a)-ord('A')
return ord(a)-ord('a')
def to_letter(n):
if n > 25:
return chr(n-26+ord('A'))
return chr(n+ord('a'))
mat = [
[0]*k for _ in range(k)
]
for letter1, letter2 in zip(ciphering, sol):
mat[from_letter(letter1)][from_letter(letter2)] += 1
cost_matrix = []
for row in mat:
cost_row = []
for col in row:
cost_row += [sys.maxsize - col]
cost_matrix += [cost_row]
m = Munkres()
indexes = m.compute(cost_matrix)
total = 0
for row, column in indexes:
value = mat[row][column]
total += value
print(total)
for row, column in indexes:
print(to_letter(column), end='')
print()

View File

@ -0,0 +1,16 @@
import random
def to_letter(n):
if n > 25:
return chr(n-26+ord('A'))
return chr(n+ord('a'))
n, k = 500000, 30
print(n, k)
for i in range(n):
print(to_letter(random.randint(0, k-1)), end="")
print()
for i in range(n):
print(to_letter(random.randint(0, k-1)), end="")
print()