#include<string>
#include<queue>
#include<vector>
#include<iostream>
struct Tire {
int son[26];
int fail;
};
std::queue<int>que;
std::vector<Tire>tire;
std::string getin;
int lenth;
void BuildTireTree(int n, int k) {
if (k == lenth) {
return;
}
tire[n].son[getin[k] - 'a'] = n + 1;
tire.push_back(Tire{0});
BuildTireTree(n + 1, k + 1);
}
void IniFail() {
que.push(1);
for (int i = 0; i < 26; i++) {
tire[0].son[i] = 1;
}
tire[0].fail = 1;
while (!que.empty()) {
int head = que.front();
for (int i = 0; i < 26; i++) {
if (tire[head].son[i]) {
tire[tire[head].son[i]].fail = tire[tire[head].fail].son[i];
que.push(tire[head].son[i]);
} else {
tire[head].son[i] = tire[tire[head].fail].son[i];
}
}
que.pop();
}
}
void Find(int n) {
if (tire[n].fail != 0) {
Find(tire[n].fail);
std::cout << n - 1 << " ";
}
}
int main() {
while (std::cin >> getin) {
tire.clear();
lenth = getin.size();
tire.push_back(Tire{0});
tire.push_back(Tire{0});
BuildTireTree(1, 0);
IniFail();
Find(lenth + 1);
std::cout<<"\n";
}
return 0;
}
what happened??WDF??