Interesting Programming Problem from Codechef.


Everyone would be aware of CodeChef.Here's is a challenging problem from CodeChef.QUES: How to measure the difference between two strings? This is a midnight question of biological scientists. The number of pairs of different characters in the same position may be a good indicator. However, it will not work well in the case when two strings have different lengths. The longest common subsequence will also fail when strings are too long. Recently, Professor of Math L.P.C. has invented the special method to deal with this problem. His invention has been known as a simple but creative solution: the difference is based on the number of substrings (a non-empty group of consecutive characters) of one string that arenot substrings of the other string. Let's learn about his invention. Call the first string as 'A' and the second string as 'B'. Let 'S' be the set of all different substrings of 'A', and 'T' be the set of all different substrings of 'B'. We then define another set 'P' which consists of all the strings that belongs to 'S' or 'T', but not both. According to the Professor L.P.C. method, the size of 'P' is a good indicator to measure the difference betweenAandB. For example, let 'A' = aacd and B = cdaa. We can see that: S = {a, aa, aac, aacd, ac, acd, c, cd, d}, T = {c, cd, cda, cdaa, d, da, daa, a, aa}, P = {aac, aacd, ac, acd, cda, cdaa, da, daa}. Size of P is 8and we can say the level of difference between A and B is 8. Your task is to find this indicator. INPUT : The first line of the input contains the string A. The secondline contains the string B. OUTPUT : Output a single line containing the level of difference between strings A and B according to definition above. Constraints *.1≤|A|≤100000, where |A| denotes the length of the string A *.1≤|B|≤100000 *.Both A and B consist only of lowercase English letters (from 'a' to 'z') Example INPUT: aacdcdaa OUTPUT:8
Related Posts Plugin for WordPress, Blogger...