> 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)))
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET 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?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
