AcWing 4183. 前后缀字符串
原题链接
简单
作者:
XnX
,
2024-07-22 22:12:58
,
所有人可见
,
阅读 2
#include <iostream>
#include <cstring>
using namespace std;
typedef unsigned long long ULL;
const int N = 4e5 + 10,P = 131;
char str[N];
ULL s[N],p[N];
ULL find(int l,int r){
return s[r] - s[l - 1] * p[r - l + 1];
}
int main(){
while (cin >> str + 1){
p[0] = 1;
for (int i = 1;str[i];i ++){
s[i] = s[i - 1] * P+ str[i];
p[i] = p[i - 1] * P;
}
int tmp = strlen(str + 1);
int l = 1,r = strlen(str + 1);
while (l <= tmp){
if (find(1,l) == find(r,tmp)){
cout << l << ' ';
}
l ++,r --;
}
cout << endl;
}
return 0;
}