#ACSL1920S2. ACSL1920S2
ACSL1920S2
PROBLEM: Given 2 strings, calculate the ACSL Difference Factor (ADF). The rules are:
• Ignore all non-alphabetic characters and convert all letters to uppercase.
• Find the longest common substring contained in the two strings. If there is more than one longest substring, use the one that is alphabetically first. If the same longest substring occurs more than once in a string, use the leftmost occurrence.
• Remove that substring from both strings.
• Separate each string into two parts, one to the left and the other to the right of the now deleted common substring. Take the left part of both strings and repeat the process to find and delete the longest common substring. Do the same to the right part of both strings.
• Repeat the process above until no new pair contains a common substring.
• The ADF is the sum of the lengths of all of the longest common substrings found.
The common substrings are: HOME, GO, I, and N. The ADF = 4 + 2 + 1 + 1 = 8.
INPUT: There will be 5 inputs. Each input contains 2 strings separated by a carriage return, each fewer than 200 characters. Blank lines in the Sample Input are for illustration only and not in the actual file.
OUTPUT: For each input, print the ADF as described above.
SAMPLE INPUT:
I am going home now
I will go home now
The big black bear bit a big black bug
The big black bug bled black blood
Complementary angle measures sum to 90 degrees.
The measures of supplementary angles add to 180 degrees.
A Tale of Two Cities was published by Dickens in 1859.
In 1839, Charles Dickens published Nicholas Nickleby.
Connecticut is The Constitution State.
Hartford is the capital of Connecticut.
SAMPLE OUTPUT:
10
19
26
18
11