Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- #define MAX 100005
- int pi[MAX];
- void pi_fun(string str)
- {
- for(int i=1;i<str.size();i++){
- int j=pi[i-1];
- while(j>0 && str[i] != str[j])
- j=pi[j-1];
- if(str[i]==str[j])
- j++;
- pi[i]=j;
- }
- }
- int main()
- {
- int i;
- string str;
- cin>>str;
- pi_fun(str);
- for(i=0;i<str.size();i++)
- cout<<pi[i]<<' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement