wes d2a2ba9e15 first commit | пре 4 година | |
---|---|---|
.. | ||
README.md | пре 4 година | |
code.cpp | пре 4 година | |
unitTest.cpp | пре 4 година |
by Helen Yu tags: strings, loops
Given two words, the letter distance is calculated by taking the absolute value of the difference in character codes and summing up the difference. If one word is longer than another, add the difference in lengths towards the score. To illustrate: letterDistance("house", "fly") = dist("h", "f") + dist("o", "l") + dist("u", "y") + dist(house.length, fly.leng
Given two words, the letter distance is calculated by taking the absolute value of the difference in character codes and summing up the difference.
If one word is longer than another, add the difference in lengths towards the score.
To illustrate:
letterDistance("house", "fly") = dist("h", "f") + dist("o", "l") + dist("u", "y") + dist(house.length, fly.length)
= |104 - 102| + |111 - 108| + |117 - 121| + |5 - 3|
= 2 + 3 + 4 + 2
= 11
letterDistance("sharp", "sharq") ➞ 1
letterDistance("abcde", "Abcde") ➞ 32
letterDistance("abcde", "bcdef") ➞ 5