如果一个单词通过循环右移获得的单词,我们称这些单词都为一种循环单词。 例如:picture 和 turepic 就是属于同一种循环单词。 现在给出n个单词,需要统计这个n个单词中有多少种循环单词。
输入描述:
输入包括n+1行: 第一行为单词个数n(1 ≤ n ≤ 50) 接下来的n行,每行一个单词word[i],长度length(1 ≤ length ≤ 50)。由小写字母构成
输出描述:
输出循环单词的种数
示例1
输入
5 picture turepic icturep word ordw
输出
2
num=int(input())
word=[]
for i in range(num):
word.append(input())
i=0
while i<len(word):
test=word[i]+word[i]
j=i+1
while j<len(word):
if len(word[i])==len(word[j]) and word[j] in test:#检测循环。而且两个单词长度要相等,防止子串的情况
del word[j] #如果是循环,从数组中删除
else:
j=j+1
i=i+1
print(len(word))