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
# Use slicing, loop and startswith() to solve the problem
# Using loop + slicing + startswith()
import re
#string initialization
str1 =input("Enter the first string\t")
str2 = input("Enter the second string \t")
# The strings entered are printed
print("The first string is : " + str(str1))
print("The second string is : " + str(str2))
overlapping = ''
for row in range(len(str1)):
# Getting prefix using startswith() function
if str2.startswith(str1[row:]):
overlapping = str1[row:]
break
# Displaying the result
if len(overlapping) ==0:
print(" No Overlapped String")
else:
print("Overlapped String : " + str(overlapping))
Comments
Leave a comment