#K32807. Minimum Transformation Cost
Minimum Transformation Cost
Minimum Transformation Cost
You are given two strings s1
and s2
of equal length n. Your task is to compute the minimum cost required to transform the source string s1
into the target string s2
by replacing each character in s1
with the corresponding character in s2
.
The cost of replacing a character a with a character b is defined as the absolute difference between their ASCII values. In mathematical terms, the cost for one character replacement is:
$|\text{ord}(a) - \text{ord}(b)|$
Your task is to calculate the sum of these individual costs over all positions in the strings.
Note: Both strings have the same length n.
inputFormat
The input consists of three lines:
- The first line contains an integer
n
representing the length of the strings. - The second line contains the source string
s1
. - The third line contains the target string
s2
.
outputFormat
Output a single integer representing the minimum transformation cost to convert s1
into s2
.
4
abcd
bcda
6