20240418
This commit is contained in:
29
ACMOJ-1477.cpp
Normal file
29
ACMOJ-1477.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <stack>
|
||||
using namespace std;
|
||||
const int kMaxN = 1e6 + 10;
|
||||
char s[kMaxN];
|
||||
int len = 0;
|
||||
int Next[kMaxN];
|
||||
int main() {
|
||||
#ifdef local
|
||||
freopen("pro.in", "r", stdin);
|
||||
#endif
|
||||
scanf("%s", s + 1);
|
||||
len = strlen(s + 1);
|
||||
for (int i = 2, j = 0; i <= len; i++) {
|
||||
while (j > 0 && s[i] != s[j + 1]) j = Next[j];
|
||||
if (s[i] == s[j + 1]) j++;
|
||||
Next[i] = j;
|
||||
}
|
||||
stack<int> res;
|
||||
for (int p = len; p > 0; p = Next[p]) res.push(p);
|
||||
while(!res.empty())
|
||||
{
|
||||
printf("%d\n",res.top());
|
||||
res.pop();
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user