Question A:
Give a string of length n, Operation: In any position of the string (or before and after the insertion of a character, so that it becomes a palindrome string,
And even if the string itself is a palindrome, you must also insert a character.
If it is not possible to achieve the goal, output "NA"
Because test instructions n<=10, so direct violence.
1. See if it is a palindrome
2. If not, then violence:
Before and after each time the string to remove a character, to see whether the newly formed string is a palindrome string, if the character is removed in the corresponding position of the character, or palindrome string, to achieve the purpose.
If not, you cannot achieve the goal of exporting "NA"
My problem with this code: s subscript starting from 0, the newly formed string subscript starting from 1, resulting in a very disordered. Originally wanted to change, good sleepy Ah, sleep.
1#include <cstdio>2#include <cstring>3 Chars[ One];4 intMain ()5 {6 while(SCANF ("%s", &s)! =EOF) {7 intlen=strlen (s);8 BOOLCnt=true;9 for(intI=1; i<=len/2; i++)Ten if(s[i-1]!=s[len-i]) { OneCnt=false; A Break; - } - if(CNT) { the for(intI=1; i<=len/2; i++) -printf"%c", s[i-1]); -printf"%c", s[len/2]); - for(inti=len/2+1; i<=len;i++) +printf"%c", s[i-1]); -printf"\ n"); + Continue; A } at for(intI=1; i<=len;i++){ - Chart[ One]; - intj=0, k=1; - while(j<Len) { - if(j==i-1) -J + +; in Else{ -t[k++]=S[j]; toJ + +; + } - } the BOOLflag=true; * for(intL=1; l<k;l++){ $ if(t[l]!=t[k-L]) {Panax Notoginsengflag=false; - Break; the } + } A if(flag) { thei--; + if(i<=len/2){ - for(intL=0; l<len-i;l++) $printf"%c", S[l]); $printf"%c", S[i]); - for(intl=len-i;l<len;l++) -printf"%c", S[l]); theprintf"\ n"); - GotoLoop;Wuyi } the Else{ - for(intL=0; l<len-i-1; l++) Wuprintf"%c", S[l]); -printf"%c", S[i]); About for(intl=len-i-1; l<len;l++) $printf"%c", S[l]); -printf"\ n"); - GotoLoop; - } A } + } theprintf"na\n"); - loop:; $ } the return 0; the}
question a
Codeforces Round #286 (Div. 2)