the palindrome

This is a discussion on the palindrome within the C++ Programming forums, part of the General Programming Boards category; /* this program from a master's blog but i don't know what dose it work,hope that somebody will explain this ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Location
    china
    Posts
    16

    Unhappy the palindrome

    /*
    this program from a master's blog but i don't know what dose it work,hope
    that somebody will explain this working detailedly(may be related to the
    palindrome ).

    this's about descriptions to be solved quesion:

    Catcher to be an agent of MCA country,he have been found any symmetrical code
    that enemy states used to comunicate with,such as:
    ABBA,ABA,A,123321 .


    but they sometimes encoded into irrelevant characters to prevent others contry
    's crack,such as the following Variants:
    ABBA->12ABBA,ABA->ABAKK,123321->51233214

    because of being intercepted characters to be too long,and with vary situation(abaab
    seems to be aba ,or baaab),of catcher ' s a great deal of working ,he have
    to get master helping,could you find out the lengthest vaild characters?


    */
    Code:
    #include <stdio.h> 
    #include <string.h> 
    #include <memory.h> 
    //#include <assert.h> 
    #define MAX_LEN 80 
    char szInput[MAX_LEN+1]; 
    unsigned char B[(MAX_LEN+1)*MAX_LEN/8];
    unsigned char Bit8={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
    #define GETB(i,j) (B[(i)*10+((j)>>3)] & Bit8[(j) & 0x7]) 
    #define SETB(i,j) (B[(i)*10+((j)>>3)] |= Bit8[(j) & 0x7]) 
    int length; 
    int getcode() 
    { 
    int i,j,notfound1,notfound2=0; 
    if(length <2) 
    return 1; 
    memset(B,0,(length+1)*10);//MAX_LEN/8? 
    for(i=0;i <2;++i) 
    { 
    for(j=0;j <length;++j) 
    SETB(i,j);//B[j]=1; 
    } 
    for(i=2;i <=length;++i) 
    { 
    for(notfound1=1,j=0;j <=length-i;++j) 
    { 
    if(GETB(i-2,j+1)/*B[i-2][j+1]*/ && szInput[j]==szInput[j+i-1]) 
    { 
    SETB(i,j);//B[j]=1; 
    //printf("&#37;d,%d = 1\n",i,j); 
    notfound1=0; 
    } 
    } 
    if(notfound1) 
    { 
    if(notfound2) 
    return i-2; 
    notfound2=1; 
    } 
    else 
    { 
    notfound2=0; 
    } 
    } 
    if(notfound2) 
    return length-1; 
    return length; 
    } 
    
    int main(void) 
    { 
    
    while(scanf("%s",szInput)!=EOF) 
    { 
    length=strlen(szInput); 
    //assert(length <=MAX_LEN); 
    printf("%d\n",getcode()); 
    } 
    return 0; 
    }




    help.........................................pleas e
    Last edited by haochao; 10-11-2008 at 07:19 AM.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    china
    Posts
    16
    maybe i describe something wrong????????????????????????????????????????????? ???????????
    tell me!

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,489
    1. Don't spam - the palindrome
    2. Don't bump unless you have something useful to add to your post
    3. Don't be in such a bloody hurry. You're not paying for 247 support here.
    4. Learn some punctuation skills. Falling asleep on the ? key makes you look like a doofus.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in Recursive String Palindrome Code
    By clegs in forum C Programming
    Replies: 13
    Last Post: 12-21-2008, 11:36 AM
  2. Is it a Palindrome?
    By xp5 in forum C Programming
    Replies: 3
    Last Post: 09-06-2007, 05:26 AM
  3. bool palindrome definition
    By justinc911 in forum C++ Programming
    Replies: 3
    Last Post: 11-26-2003, 04:50 PM
  4. Palindrome Coding trouble
    By TheLoneWolf32 in forum C++ Programming
    Replies: 3
    Last Post: 02-22-2003, 06:05 PM
  5. palindrome HELP !!!
    By TED22_8 in forum C Programming
    Replies: 23
    Last Post: 01-22-2002, 01:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21