传送门:POJ2752
傻逼题,注意前缀函数的定义就行了。
代码上的小细节见下。
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int ans[1000005];
int f[1000005];
int tot;
void Make_Table(string a)
{
f[0]=-1;int k=-1,len=a.length();
for(int i=1;i<len;i++){
while(k>=0&&a[k+1]!=a[i])
k=f[k];
if(a[k+1]==a[i])
k++;
//printf("%d\n",i);
f[i]=k;
}
}
void GetAns(string a)
{
int i=a.length();
i--;
while(i!=-1){
if(a[i]!=a[a.length()-1])
break;
ans[++tot]=i+1;
i=f[i];
}
for(int j=tot;j>=1;j--)
printf("%d ",ans[j]);
printf("\n");
}
void Solve()
{
freopen("loli.in","r",stdin);
string a;
while(cin>>a){
Make_Table(a);
GetAns(a);
tot=0;
}
}
void Close()
{
fclose(stdin);
fclose(stdout);
}
int main()
{
Solve();
Close();
return 0;
}