题目1434:蓝桥杯历届试题-回文数字

#include<iostream>

using namespace std;

//计算各位之和

int totalSum(int x){

int sum=0;

while(x>0){

sum+=x%10;

x/=10;

}

return sum;

}

//判断是否为回文数

bool isPolindromt(int x){

int orignal=x,reversed=0;

while(x>0){

reversed=reversed*10+x%10;

x/=10;

}

return orignal==reversed;

}

int main(){

int n;

cin>>n;

bool found=false;

for(int i=10000;i<=999999;i++){

if(isPolindromt(i)&&totalSum(i)==n){

cout<<i<<endl;

found=true;

}

}

if(!found){

cout<<-1<<endl;

}

return 0;

}

相关推荐
星火开发设计2 小时前
格式化输入输出:控制输出精度与对齐方式
开发语言·c++·学习·算法·函数·知识
ygklwyf2 小时前
模拟退火算法零基础快速入门
数据结构·c++·算法·模拟退火算法
XX風2 小时前
3.3 GMM (高斯混合模型)
人工智能·算法·机器学习
zy_destiny2 小时前
【工业场景】用YOLOv26实现8种道路隐患检测
人工智能·深度学习·算法·yolo·机器学习·计算机视觉·目标跟踪
寄存器漫游者2 小时前
数据结构 二叉树与哈希表
数据结构·散列表
zmzb01032 小时前
C++课后习题训练记录Day91
开发语言·c++
怡步晓心l2 小时前
Mandelbrot集合的多线程并行计算加速
c++·算法·缓存
老鼠只爱大米2 小时前
LeetCode经典算法面试题 #114:二叉树展开为链表(递归、迭代、Morris等多种实现方案详细解析)
算法·leetcode·二叉树·原地算法·morris遍历·二叉树展开
今儿敲了吗2 小时前
07| 高精度除法
c++