字符串逆置

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

//字符串逆置

void inverse01(char*ch)

{

  int i=0;

  int j=strlen(ch)-1;

  while(i<j)

  {

    char temp=ch[i];

    ch[i]=ch[j];

    ch[j]=temp;

    i++;

    j--;

  }

  return ;

}

void inverse(char*ch)

{

  char*ftemp=ch;

  char*btemp=ch+strlen(ch)-1;

  while(ftemp<btemp)

  {

    char temp=*ftemp;

    *ftemp=*btemp;

    *btemp=temp;

    ftemp++;

    btemp--;

  }

  return;

}

int main0101()

{

  char ch[]="hello world";

  inverse(ch);

  printf("%s ",ch);

  return EXIT_SUCCESS;

//结果

}

//回文字符串       abcba   abccba      abcbdcba//err

int symm01(char*ch)

{

  int i=0;

  int j=strlen(ch)-1;

  while(ch[i]==ch[j])

  {

// i>j:偶数;i==j:奇数; 

    if(i>j || i==j)

    {

      return 1;

    }

    i++;

    j--;

  }

  return 0;

}

int symm(char*ch)

{

  char*ftemp=ch;

  char*btemp=ch+strlen(ch)-1;

  while(ftemp<btemp)

  {

    if(*ftemp!=*btemp)

    {

      return 0;

    }

    ftemp++;

    btemp--;

  }

  return 1;

}

int main()

{

  char ch[]="abccba";

  int value=symm(ch)

  if(value)

  {

    printf("相同 ");

  }

  else

  {

    printf("不相同 ");

  }

  return 0;

}

原文地址:https://www.cnblogs.com/wanghong19991213/p/13609281.html