Codeforces Round #286 (Div. 2)

Source: Internet
Author: User

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)

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.