0
点赞
收藏
分享

微信扫一扫

循环单词

如果一个单词通过循环右移获得的单词,我们称这些单词都为一种循环单词。 例如: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
示例2
输入
4
goran
igor
domagoj
relja
输出
4
说明
并不是必须包含两个或两个以上的不同单词才算一种循环单词!

n = int(input())
words = []
for i in range(n):
words.append(input())
def fun(s):
ans = set()
for i in range(len(s)):
tmp = s[i:]+s[:i]
ans.add(tmp)
return ans
res = []
for word in words:
if fun(word) not in res:
res.append(fun(word))
print(len(res))
举报

相关推荐

0 条评论