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

}

相关推荐
不会就选b2 小时前
算法日常・每日刷题--<贪心>14
算法
初願致夕霞2 小时前
C++11:类型推导与完美转发复盘笔记
c++
小猪写代码2 小时前
C++中什么是类,什么是对象
c++
mmmmath_34 小时前
LeetCode.541.反转字符串II
数据结构·算法·leetcode
Navigator_Z5 小时前
LeetCode //MySQL - 1251. Average Selling Price
c语言·算法·leetcode
醇氧6 小时前
MySQL 8.0 系统表损坏与引擎转换故障排查实战
数据结构·算法
大熊背6 小时前
《Color constancy by characterization of illumination chromaticity》之色度色域最大化算法(二)
算法·白平衡·色度·色温
钓鱼的肝6 小时前
梳理(1-5)
c++·经验分享·笔记·算法·青少年编程
HZZD_HZZD6 小时前
CSDN_批发市场水电漏损归因算法LAM的原理与落地
嵌入式硬件·物联网·算法