zoukankan      html  css  js  c++  java
  • 字符串逆置

    #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;

    }

  • 相关阅读:
    UIWebView控件中 字体大小和字体样式的修改
    IOS statusBarStyle 设置
    SSZipArchive解压失败的原因
    uiimageview 的 animation 动画
    App网络管理
    系统日志输出工具类
    软键盘管理
    获取App应用信息
    Activity管理类
    SharePreference工具类
  • 原文地址:https://www.cnblogs.com/wanghong19991213/p/13609281.html
Copyright © 2011-2022 走看看