#include<iostream>
using namespace std;
int reverse(int num){
int temp=0;
while (num){
temp += num % 10;
if (num/10)
temp = temp * 10;
num = num/10;
}
return temp;
}
int main(){
int count,k;
long int num1,num2[500];
while (cin>>num1){
count = 0;
while (true){
if (num1 == reverse(num1))
{
break;
}
else{
num2[count] = num1;
count++;
num1 += reverse(num1);
}
}
num2[count] = num1;
cout << count << endl;
k = 1;
for (int i = 0; i <= count; i++){
if (k)
{
cout << num2[i]; k = 0;
}
else
cout << "--->" << num2[i];
}
cout << endl;
}
return 0;
}
一开始,想法是用数组保存,但后来发现,数组保存涉及的加法更加复杂。
HDJacm 1282 回文数猜想
最新推荐文章于 2023-07-25 18:26:35 发布