首页 > 试题广场 >

最小循环节

[编程题]最小循环节
  • 热度指数:3960 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 512M,其他语言1024M
  • 算法知识视频讲解
\hspace{15pt}给定一个长度为 n 、由大小写字母混合构成的字符串 s,你可以无限次的往字符串的任何地方插入任意字符。求新字符串 s最小循环节

\hspace{15pt}对于字符串 b ,找到最短长度的子串 a ,使得字符串 b 是由子串 a 拼接若干次得到的,即 b=aa \cdots a 。这里的子串 a 的长度即为字符串 b最小循环节

输入描述:
\hspace{15pt}在一行上输入一个长度不超过 10^5 、由大小写字母混合构成的字符串 s ,代表初始字符串。


输出描述:
\hspace{15pt}在一行上输出一个整数,代表字符串 s 的最小循环节的长度。
示例1

输入

abcabcD

输出

4

说明

\hspace{15pt}在字符串 \texttt{ 中,最小循环节为 \texttt{ ,其长度为 4 。
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    while ((line = await readline())) {
        let tokens = line.split("");

        const arr = new Set(tokens);
        const _arr = Array.from(arr);
        
        return _arr.length;
    }
})();
发表于 2025-04-04 22:58:18 回复(0)