1 Star 0 Fork 0

南陽劉子驥 / OI Codes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ac141.cpp 677 Bytes
一键复制 编辑 原始数据 按行查看 历史
南陽劉子驥 提交于 2022-06-15 14:11 . 20220615
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<int> kmp(string s)
{
int n = ( int )s.length();
vector<int> pi(n);
for(int i = 1; i < n; i++)
{
int j = pi[i - 1];
while(j > 0 && s[i] != s[j]) j = pi[j - 1];
if(s[i] == s[j]) j++;
pi[i] = j;
}
return pi;
}
int main()
{
int n;
string s;
cin >> n;
int tot = 0;
while(n)
{
cin >> s;
vector<int>pi = kmp(s);
printf("Test case #%d\n", ++tot);
for(int i = 0; i < n; i++)
if(((i + 1) % (i - pi[i] + 1) == 0) && ((i + 1) != (i - pi[i] + 1)))
printf("%d %d\n", i + 1, (i + 1) / (i - pi[i] + 1));
putchar('\n');
cin >> n;
}
return 0;
}
1
https://gitee.com/kaiserwilheim/OIcodes.git
git@gitee.com:kaiserwilheim/OIcodes.git
kaiserwilheim
OIcodes
OI Codes
master

搜索帮助