Monday, March 1, 2010

PALINDROME

INPUT            : ANY STRING

OUTPUT         : SHOULD CHECK IF IT IS A PALINDROME ARE NOT

         POSTER       :  PUJA
PAlindrome ->string when reverse also provides same kind example :MALAYALAM solutions:

BY SANTOSH

#include "stdafx.h"
#include
#include "stdlib.h"
#include "string"

int CheckPalindrome(char *);

int _tmain(int argc, _TCHAR* argv[])
{
       char *pString = NULL;
      
       bool chkStatus = FALSE;
      
       pString = (char *)malloc(10*sizeof(char));

       if(!pString)
       {
              printf("Memory Allocation Failed\n");
              exit(EXIT_FAILURE);
       }
       printf("Enter the string to be checked:\n");
       scanf("%s",pString);

       chkStatus = CheckPalindrome(pString);

       if(chkStatus)
              printf("The entered string is Palindrome\n");
       else
              printf("The entered string is not Palindrome\n");

       free(pString);

       return 0;
}

int CheckPalindrome(char *pSrc)                        //Function works irrespective of case senstivity
{
       int chkCnt1,chkCnt2,strLen;

       chkCnt1 = chkCnt2 = 0;

       strLen = strlen(pSrc);

       for(chkCnt1 = 0,chkCnt2 = strLen - 1;(chkCnt1!=chkCnt2) && (chkCnt1 < chkCnt2);chkCnt1++,chkCnt2--)
       {
              if((*(pSrc + chkCnt1) != *(pSrc + chkCnt2)) && (*(pSrc + chkCnt1) != *(pSrc +chkCnt2) - 32) && (*(pSrc + chkCnt1) != *(pSrc + chkCnt2) + 32))
                     return FALSE;
       }

       return TRUE;

}
BY AVINASH



#include"stdio.h"
#include"string"
#include"stdlib.h"
//-----MEMORY USED :1 block of memory for string,3 ints for tracking the string,
//                   2 ptrsto track Start and LAst position
//-----LOOPS       : FOR loop - which loops for half of string.   


//--------MACRO DEFINATION START---------//
#define __DEBUG__
#define __FUNCTION_TRUE__ 0
#define __FUNCTION_FALSE__ 1


//--------GLOBAL DECLARATION START-------//
int myPalindromeChk(char *);


//-------MAIN FUNCTION---------//
int main()
{
       char *pszInputstr = NULL;
    pszInputstr       = (char*)malloc(40*sizeof(char));
       if((char*)NULL == pszInputstr )
       {
#ifdef __DEBUG__
  printf("\n--Memory Allocation for pszInputstr FAILED on line %d--\n", __LINE__);
           return 0;         //CORRECTED BY RAJESH
#endif
       }
       printf("Enter  to find it as palindrome");
       scanf("%s", pszInputstr);
    if(__FUNCTION_TRUE__ == myPalindromeChk(pszInputstr))
             printf("\n PALINDROMED STRING");
       else
             printf("\n NOT A PALINDROMED");

      
       return 0;
}

//------Functions----------------//
int myPalindromeChk(char *pName)
{     
       char *plast =NULL;
       char *pfirst = pName;
       int iCount = 0;
       int ichk = 0;
       int iNameLen = strlen(pName);
       plast = iNameLen + pName-1;
             for(iCount = 1; iCount <= iNameLen/2 && (*pfirst == *plast); pfirst++, plast--,iCount++)
                    ichk++;
             if(ichk == iNameLen/2)
                    return __FUNCTION_TRUE__;
             else
                    return __FUNCTION_FALSE__;
       return 0;
}

No comments:

counter