1.写一函数int fun(char *p)判断一字符串是否为回文,是返回1,不是返回0,出错返回-1
//答案:一、
int fun(char *p)
{
if(p==NULL)
return -1;
else
{
int length = 0;
int i = 0;
int judge = 1;
length = (int)strlen(p);
for(i=0; i <length/2; i++)
{
if(p[i] != p[length-1-i])
judge = 0;
break;
}
if(judge == 0)
return 0;
else
return 1;
}
//答案:二、
int fun1(char *p)
{
if(p==NULL)
return -1;
int len = (int)strlen(p) - 1;
char *q = p + len;
while (p < q)
{
if ((*p++) != (*q--))
return 0;
}
return 1;
}
//答案:一、
int fun(char *p)
{
if(p==NULL)
return -1;
else
{
int length = 0;
int i = 0;
int judge = 1;
length = (int)strlen(p);
for(i=0; i <length/2; i++)
{
if(p[i] != p[length-1-i])
judge = 0;
break;
}
if(judge == 0)
return 0;
else
return 1;
}
//答案:二、
int fun1(char *p)
{
if(p==NULL)
return -1;
int len = (int)strlen(p) - 1;
char *q = p + len;
while (p < q)
{
if ((*p++) != (*q--))
return 0;
}
return 1;
}