首页 技术 正文
技术 2022年11月23日
0 收藏 627 点赞 2,357 浏览 853 个字

Problem Description

一个正整数,如果从左向右读(称之为正序数)和从右向左读(称之为倒序数)是一样的,这样的数就叫回文数。任取一个正整数,如果不是回文数,将该数与他的倒序数相加,若其和不是回文数,则重复上述步骤,一直到获得回文数为止。例如:68变成154(68+86),再变成605(154+451),最后变成1111(605+506),而1111是回文数。于是有数学家提出一个猜想:不论开始是什么正整数,在经过有限次正序数和倒序数相加的步骤后,都会得到一个回文数。至今为止还不知道这个猜想是对还是错。现在请你编程序验证之。

Input

每行一个正整数。

特别说明:输入的数据保证中间结果小于2^31。

Output

对应每个输入,输出两行,一行是变换的次数,一行是变换的过程。

Sample Input

27228

37649

Sample Output

3

27228—>109500—>115401—>219912

2

37649—>132322—>355553

代码:

#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
int cmp(int x)
{
int n=0;
while(x!=0)
{n=n*10+x%10;
x=x/10;
}
return n;
}
int main()
{
int n,m,i,j,k;
int a[1000];
while(cin>>n)
{ i=1;
a[0]=n;
while(i)
{m=cmp(a[i-1]);
if(m!=a[i-1])
{
m=m+a[i-1];
a[i]=m;
i++;
}
else break;
}
cout<<i-1<<endl;
cout<<a[0];
for(j=1;j<=i-1;j++)
cout<<"--->"<<a[j];
cout<<endl;}
return 0;
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,994
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,507
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,350
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,135
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,768
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,845