Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int prefix[200005];
- string rev,text;
- int len,len1,cnt;
- void compute_prefix()
- {
- int i,j=0;
- for(i=1; rev[i]; i++)
- {
- while(j && rev[j]!=rev[i])
- {
- j = prefix[j];
- }
- if(rev[j]==rev[i])
- {
- j++;
- }
- prefix[i+1] = j;
- }
- }
- void KMP_match()
- {
- int i,j=0;
- for(i=0; i<len; i++)
- {
- while(j && rev[j]!=text[i])
- {
- j = prefix[j];
- }
- if(rev[j]==text[i])
- {
- j++;
- }
- if(j==len1)
- {
- cnt++;
- j = prefix[j];
- }
- }
- }
- int main()
- {
- int test,i;
- scanf("%d",&test);
- while(test--)
- {
- cin>>rev;
- text = "";
- text = rev+rev;
- reverse(rev.begin(),rev.end());
- len = text.length();
- len1 = rev.length();
- cnt = 0;
- compute_prefix();
- KMP_match();
- if(cnt==2)
- {
- printf("palindrome\n");
- }
- else if(cnt>2 || cnt==1)
- {
- printf("alindrome\n");
- }
- else
- {
- printf("simple\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment