解题思路:
本体略微不同于另一个求字符串中的子串最大周期的题:
1.本题中的字符串一定是k个子串拼接成的,不能有无关字符(即不能用字符串中的count方法);
2.本题中的输出结果是所有可以构成周期串中的子串的最小长度;
3.非周期串直接输出该串的长度即可。
注意事项:
参考代码:
n, res = input(), [] for i in range(1, len(n)): temp = n.split(n[:i]) temp_len = len(temp) temp_len_test = sum(1 for i in temp if i == '') if temp_len == temp_len_test: res.append(i) if res: print(min(res)) else: print(len(n))
0.0分
1 人评分