Hint:
The ring of <Example Input 2> contains a string called "XYZ".This is because the beginning and end of the ring string are connected.
The first ring of <Example Input 3> contains two words "PQR", the second ring contains one string "PQR", and the third ring does not contain the string "PQR".Therefore, the number of rings containing the string "PQR" becomes two.
Code:
string = input()
cnt = 0
allwords = []
for i in range(int(input())):
allwords.append(input() * 2)
for i in allwords:
if string in i:
cnt += 1
print(cnt)
We first get the input of the string that you want to search for. We make a counting variable called cnt. We also make a list called allwords to store the whole words.
string = input()
cnt = 0
allwords = []
Because rings meet each other at one point, we have to times the whole string by two.
for i in range(int(input())):
allwords.append(input() * 2)
At last, we got to check if the string is inside the sentence and add 1 to cnt variable if each appear.
for i in allwords:
if string in i:
cnt += 1
print(cnt)