You are viewing a single comment's thread. Return to all comments →
Try this code u will get the answer
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ char a[100007]; int size; cin>>size;
while(size) { cin>>a; int l=strlen(a); int i=0,j=l-1; if(l%2==0) { for(i=0;i<j;i++) { if(a[i]==a[j]) { j--; if(i==j) { cout<<"-1"; break; } } else if(a[i+1]==a[j]) { cout<<i; break; } else { cout<<j; break; } } } else { for(i=0;i<=j;i++) { if(a[i]==a[j]) { j--; if(i==j) { cout<<"-1"; break; } } else if(a[i+1]==a[j]&& a[j-1]==a[i]) { if(a[i+2]==a[j-1]) { cout<<i; break; } else { cout<<j; break; } } else if(a[i+1]==a[j]) { cout<<i; break; } else { cout<<j; break; } if(i+1==j) { cout<<"-1"; break; } } } cout<<"\n";
size--; } getch(); return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Palindrome Index
You are viewing a single comment's thread. Return to all comments →
Try this code u will get the answer
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
char a[100007]; int size; cin>>size;
size--; } getch(); return 0; }