#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
const int N=19;
int main()
{
int a[N];
int n;
scanf("%d",&n);
string numstd=to_string(n);//将整数转换成字符串
int i=0,j=numstd.length()-1;//字符串是从下标0开始 所以j要减一
if(n<10) //个位数直接判断为回文数
{
cout<<"是回文数";
return 0;
}
while(i<j) //从头和尾一起遍历
{
if(numstd[i]==numstd[j]) //头尾相同就靠拢
{
i++,j--;
}
if(numstd[i]!=numstd[j])
{
cout<<"不是回文数";
break;
}
else if(i==j||i>j) //一定不要忘了i>j !
{
cout<<"是回文数";
}
}
return 0;
}
回文数挑选 C语言 重庆市第六届大学生程序设计大赛
于 2023-11-20 16:38:24 首次发布