kmp才能保证不超时
#include#include #include #include #include using namespace std;void getNext(int next[],char str[]){ int j = 0; next[0] = -1; int k = -1; int len = strlen(str); while(j < len){ if(k == -1 || str[k] == str[j]){ next[++j] = ++k; } else k = next[k]; }}int main(){ //freopen("in.txt","r",stdin); char str[400001]; int next[400001]; int j; while(scanf("%s",str) != EOF){ memset(next,0,strlen(str)); getNext(next,str); stack q; j =strlen(str); while(j != 0){ q.push(j); j = next[j]; } while(!q.empty()){ printf("%d ",q.top()); q.pop(); } printf("\n"); } return 0;}