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
# input first string
str1=input('Input first string>')
# input second string
str2=input('Input second string>')
# length of the stings
len1=len(str1)
len2=len(str2)
# min length of the strings
len_min=len1
if len_min>len2:
len_min=len2
# loop for compare substrings
n=len_min
while n>0:
if str1[len1-n:len1+1]==str2[0:n]:
# print result
print(str2[0:n])
break
n-=1
# print if no result
if n==0:
print('No overlapping')
Comments
Leave a comment