#include<stdio.h>
#include<string.h> //使用strlen用到的头文件
#include<memory.h> //使用memset用到的头文件
int main()
{
char arr[30]; //初始化用char arr[30]={'0'}浪费空间
memset(arr, 0, sizeof(arr)); //通过memset来分配arr索要的空间
scanf("%s", arr);
int right= strlen(arr) - 1; //由于数组从0开始,带strlen是从1开始,所以减去1
int left= 0;
int count=1;
while (left<= (right / 2))
{
if (arr[left] == arr[right]) //比如abba
{ // 0 3这是左和右的ab索引
left++; //left=0 right=3
right--;
}
else {
count = 0;
break; //直接跳出循环
}
}
if (count == 1) {
printf("回文数");
}
else if(count==0) {
printf("不是回文数");
}
return 0;
}
回文数--前后对称
最新推荐文章于 2025-05-17 09:22:26 发布