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)