当前位置:网站首页>生成回文数
生成回文数
2022-08-04 22:25:00 【拉的很多】
题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
所谓回文数就是左右对称的数字,比如:
585,5885,123321...
当然,单个的数字也可以算作是对称的。
小明发现了一种生成回文数的方法: 比如,取数字 1919,把它与自己的翻转数相加: 19 + 91 = 110,如果不是回文数,就再进行这个过程:110+011=121 这次是回文数了。200 以内的数字中,绝大多数都可以在 30 步以内变成回文数,只有一个数字很特殊,就算迭代了1000 次,它还是顽固地拒绝回文!
请你输出该顽固数字。
思路:
主要了解 怎么如何进行逆序
long long sum = 0;
while(n)
{
int t = n % 10;
sum = sum * 10 + t;
n = n/10;
}
#include<stdio.h>
long long fan(long long n)
{
long long sum = 0;
while(n)
{
int t = n % 10;
sum = sum * 10 + t;
n = n/10;
}
return sum;
}
int main()
{
long long n;
int i,j;
for(i=1;i<200;i++)
{
n = i;
for(j=0;j<30;j++)
{
if(n != fan(n))
{
n += fan(n);
}
else
break;
}
if(j >= 30)
printf("%d\n",i);
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
QT[一] 信号与槽
养殖虚拟仿真软件提供高沉浸式的虚拟场景互动操作体验学习
打卡第 2 天: urllib简记
Use ngrok to optimize web pages on raspberry pi (1)
年薪40W测试工程师成长之路,你在哪个阶段?
历史上的今天:PHP公开发布;iPhone 4 问世;万维网之父诞生
SQL Server 调用 WebService
FinClip崁入式搭建生态平台,降低合作门槛
关于el-table列表渲染
Hardware factors such as CPU, memory, and graphics card also affect the performance of your deep learning model
一招包治pycharm DEBUG报错 UnicodeDecodeError: ‘utf-8‘ codec can‘t decode
JVM memory configuration parameter GC log
移动web开发03
重新配置chrome中ffmpeg插件
[Linear Algebra 02] 2 interpretations of AX=b and 5 perspectives of matrix multiplication
com.jacob.com.ComFailException: Invoke of: ActiveDocument
Leaflets of three bouquet of roses
shell选择结构(if)
Ts——项目实战应用enum枚举
Jbpm3.2 开发HelloWorld (简单请假流程)客户端