题目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;

}

相关推荐
6Hzlia5 分钟前
【Hot 100 刷题计划】 LeetCode 42. 接雨水 | C++ 动态规划与双指针题解
c++·算法·leetcode
地平线开发者16 分钟前
智能驾驶感知算法的演进
算法·自动驾驶
爱丽_21 分钟前
B+ 树范围查询为什么快:页分裂/合并、索引设计与 SQL 写法优化
数据库·算法·哈希算法
企鹅的蚂蚁43 分钟前
【ESP32-S3开发踩坑】C++野指针引发的LoadProhibited死机与CMake依赖锁死排查
开发语言·c++
WBluuue1 小时前
Codeforces 1087 Div2(ABCDEF)
c++·算法
Yzzz-F1 小时前
2025 ICPC武汉邀请赛 G [根号分治 容斥原理+DP]
算法
初圣魔门首席弟子1 小时前
1768. 交替合并字符串 详细题解
c++
abant21 小时前
leetcode 114 二叉树变链表
算法·leetcode·链表
tankeven1 小时前
HJ165 小红的优惠券
c++·算法
Jasmine_llq2 小时前
《B3840 [GESP202306 二级] 找素数》
开发语言·c++·试除法·顺序输入输出算法·素数判定算法·枚举遍历算法·布尔标记算法