判断字符串是否对称

来源:互联网 发布:2345软件大全app 编辑:程序博客网 时间:2024/05/17 18:02

判断字符串是否对称,且不能用字符串的系统函数。

#include <iostream.h>

int StrSymmetry(char *c)
{  
    char *x = c;
    int n=0;
   
    while(*x)
    {
        x++;
        n++;       
    }
    x--;
   
    for(int i = 0; i < n/2; i++)
    {
        if((*c)^(*x))
        {
            return 0;
        }
        else
        {
            c++;
            x--;
        }
    }
    return 1;
}

void main()
{
    char *str = "ab123321ba";

    cout<<StrSymmetry(str)<<endl;
}

原创粉丝点击