回文串判断
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 10010
#define ElemType int
void InitString(char s1
[MAXSIZE
]){
scanf("%s",s1
);
}
void CheckIsSyn(char s1
[MAXSIZE
],int length
){
int i
=-1,j
=length
;
while(s1
[++i
]==s1
[--j
]&&i
<=(j
-1));
if(i
>=j
&&length
>0)
printf("该字符串是回文串\n");
else
printf("该字符串不是回文串\n");
}
int getLength(char s1
[MAXSIZE
]){
int length
=0,index
=0;
while(s1
[index
++]!='\0'){
length
++;
}
return length
;
}
int main(){
char s1
[MAXSIZE
];
printf("输入字符串:");
InitString(s1
);
printf("存储字符串为:%s\n",s1
);
int length
=0;
length
=getLength(s1
);
printf("字符串长度为:%d\n",length
);
printf("判断是否为回文串\n");
CheckIsSyn(s1
,length
);
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-30360.html