项目场景:
`最近在看B站上有关蓝桥杯的课程,有一部分是计蒜客讲的,其中第六节快速提高代码能力的部分中讲的那个回文数个人感觉不太对,394+493=887而不是1292,于是附上自己的解题代码,还望各位大佬赐教
题目
#include<iostream>
using namespace std;
bool judge(int a)
{
int b,c,d;
c=a;
b=0;
while(a/10!=0)
{
b+=(a%10);//对末位取余
b=b*10;//腾出b的最后一位,为下次循环做准备
a=a/10;
}
b+=(a%10);
if(b==c)
return true;
else
return false;
};
int add(int a)
{
int b,c,d;
c=a;
b=0;
while(a/10!=0)
{
b+=(a%10);//对末位取余
b=b*10;//腾出b的最后一位,为下次循环做准备
a=a/10;
}
b+=(a%10);
return (c+b);
}
int main()
{
int a,ans;
int record[10000];
ans=0;
cin>>a;
while(!judge(a))
{
record[ans]=a;
ans++;
a=add(a);
}
cout<<ans<<endl;
for(int i=0;i<ans;i++)
{
cout<<record[i]<<"--->";
}
cout<<a<<endl;
return 0;
}
结果
394的运行结果并不如图所示
但题目中的57是对的