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
string1 = str(input())
string2 = str(input())
patternMatch = ""
length1, length2 = len(string1), len(string2)
for i in range(length1):
patternFound = ""
for j in range(length2):
if (i + j < length1 and string1[i + j] == string2[j]):
patternFound += string2[j]
else:
if (len(patternFound) > len(patternMatch)):
patternMatch = patternFound
patternFound = ""
print(patternMatch)
Output:
Comments
Leave a comment