蓝桥杯试题 基础练习 特殊回文数

资源限制
时间限制:1.0s   内存限制:512.0MB
问题描述
  123321是一个非常特殊的数,它从左边读和从右边读是一样的。
  输入一个正整数n, 编程求所有这样的五位和六位十进制数,满足各位数字之和等于n 。
输入格式
  输入一行,包含一个正整数n。
输出格式
  按从小到大的顺序输出满足条件的整数,每个整数占一行。
样例输入
52
样例输出
899998
989989
998899
数据规模和约定
  1<=n<=54。
#include<iostream>
#include<algorithm>
#include<vector> 
#include<cstring>
#include<string.h>
#include<queue> 
#include<map>
#include<cmath>
#define OK 1
#define ERROR 0
#define MAXSIZE 120 
#define MAX 100020
const double eps=1e-5;
const int maxn=1010;
typedef long long LL;
using namespace std;

bool IsSum(int n,int m){
    int sum=0;
    while(m){
        sum+=m%10;
        m/=10;
    }
    if(sum==n){
        return true;
    }
    else{
        return false;
    }
}
bool IsPalindrome(int n){
    string st="";
    while(n){
        st+=(n%10)+'0';
        n/=10;
    }
    int b=st.length();
    for(int i=0;i<b/2;i++)
    {
        if(st[i]!=st[b-1-i]){
            return false;
        }
    }
    return true;
}
int main(){
    int n,i;
    scanf("%d",&n);
    for(i=10000;i<=999999;i++){
        if(IsSum(n,i)){
            if(IsPalindrome(i)){
                printf("%d
",i);
            }
        }
    }
    return 0;
} 
原文地址:https://www.cnblogs.com/dreamzj/p/13673558.html