Prefix Suffix
Write a program to check the overlapping of one string's suffix with the prefix of another string.
Input
The first line of the input will contain a string A.
The second line of the input will contain a string B.
Output
The output should contain overlapping word if present else print "No overlapping".
Explanation
For example, if the given two strings, A and B, are "ramisgood" "goodforall"
The output should be "good" as good overlaps as a suffix of the first string and prefix of next.
Sample Input 1
ramisgood
goodforall
Sample Output 1
good
Sample Input 2
finally
restforall
Sample Output 2
No overlapping
A = input("Enter the first string:")
B = input("Enter the second string: ")
def overlapping(S1, S2):
output = ""
lenght1, lenght2 = len(S1), len(S2)
for i in range(lenght1):
match = ""
for n in range(lenght2):
if (i + n < lenght1 and S1[i + n] == S2[n]):
match += S2[n]
else:
if (len(match) > len(output)): output = match
match = ""
if output == '':
return 'No overlapping'
else:
return output
print(overlapping(A, B))
Comments
Leave a comment