Binshenoj 1215-i wanna be A palindrome (YY)

Source: Internet
Author: User

1215:i wanna be A palindrome time limit: 2 Sec memory limit: MB
submitted by: 148 resolution: 22
Submitted State [Discussion Version] Title Description

Gives a string that consists of lowercase letters only. Find out if you just delete one of the letters and the string becomes a palindrome.


Input

The input first line is an integer t, which indicates that there is a T Group of data. one row per group of data, each containing a non-empty string with a string length not exceeding5 .


Output

For each set of test data, the output line contains an integer k , which indicates that the K-character in the delete string becomes a palindrome string. If more than one such integer K exists, the smallest of the integers is output . If the input string is originally a palindrome string, or if no such integer is found, the output is "no solution" (without quotation marks).


Sample input
3aaababababcba
Sample output
41No Solution
Tips


ideas: From both sides to the middle sweep, encountered different characters in two cases to delete, but pay attention to not necessarily delete the two different characters to achieve palindrome, it is possible to delete other characters, such as ABBCXCBA answer is 2, not 3This situation yy, only the same character will occur, so forward enumeration can
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring>using namespace    std;const int N = 1e5+100;char a[n];bool judge (int x,int y) {int l=0;        while (x+l<=y-l) {if (a[x+l]==a[y-l]) l++;    else return false; } return true;    int main () {int T;    scanf ("%d", &t);        while (t--) {bool flag=0;        scanf ("%s", a+1);        int Len=strlen (a+1);            for (int i=1;i<=len;i++) {if (a[i]==a[len-i+1]) continue;            int j=i;            while (A[j-1]==a[i]) j--;                    for (int k=j;k<=i;k++) if (judge (k+1,len-k+1)) {printf ("%d\n", K);                    flag=1;                Break            } if (flag) break;                if (judge (I,len-i)) {printf ("%d\n", len-i+1);                flag=1;            Break        } break; } if (!flag) printf ("No solutioN\n "); } return 0;}


Binshenoj 1215-i wanna be A palindrome (YY)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.