> For the complete documentation index, see [llms.txt](https://l1nwatch.gitbook.io/interview_exercise/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://l1nwatch.gitbook.io/interview_exercise/bian-cheng-ti-hui-zong/wang-yi-2017-xiao-zhao-bi-shi-bian-cheng-ti/ping-fang-chuan.md).

# 平方串

## 题目描述

如果一个字符串由完全相同的两段字符组成，我们称其为平方串。例如：

'aa'，'ABAB'，'abcabc' 是平方串。

'aaa'，'ABCabc'，'abcab' 不是平方串。

现在给出一个字符串求它所有的连续子串中有多少种平方串。

例如：

'aaabccabccCC'，我们会发现 'aa'，'abccabcc'，'cc'，and 'CC' 这四种平方串。其中 'aa', 'cc' 都出现了 2 次，但是我们只统计一次种树。

输入描述：

> 输入为一个字符串，长度 length(0 <= length <= 50)。只包含大小写字母。

输出描述：

> 输出一个整数，即为所求的种数

输入例子：

> aaabccabccCC

输出例子：

> 4

## 自己的解答

以下这个解答只能通过示例，其他例子还没试，当时还没来得及提交就结束考试了。

```python
def is_pingfang(text):
    if len(text) == 1:
        return False
    elif len(text) % 2 != 0:
        return False
    else:
        return text[len(text) // 2:] == text[:len(text) // 2]


text = "aaabccabccCC"
result_set = list()

for i in range(len(text)):
    for j in range(1, len(text) - i + 1):
        test = text[i:i + j]
        if is_pingfang(test):
            result_set.append(test)

# print(result_set)
print(len(set(result_set)))
```
