1 条题解
-
0Guest LV 0 MOD
-
0
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; typedef unsigned long long UL; UL h[400005], mul[400005], K = 1000000031; char s[400005]; int main() { mul[0] = 1; for (int i = 1; i <= 400000; i++) //初始化每个位置的权值 mul[i] = mul[i - 1] * K; while (~scanf("%s", s + 1)) { //输入字符串 int n = strlen(s + 1); //求得字符串长度 for (int i = 1; i <= n; i++) { h[i] = h[i - 1] * K + s[i] - 'a' + 1; //计算前i个字符的哈希值 a的值为1,b的值为2,以此类推 } for (int i = 1; i <= n; i++) { if (h[i] == h[n] - (h[n - i]*mul[i])) printf("%d ", i); } putchar('\n'); } return 0; }
- 1