基础练习 特殊回文数
时间限制:1.0s 内存限制:512.0MB
问题描述 123321是一个非常特殊的数,它从左边读和从右边读是一样的。
输入一个正整数n, 编程求所有这样的五位和六位十进制数,满足各位数字之和等于n 。输入格式 输入一行,包含一个正整数n。输出格式 按从小到大的顺序输出满足条件的整数,每个整数占一行。样例输入52样例输出899998
989989
998899数据规模和约定 1<=n<=54。
public class _09_特殊回文数 {
// 12221
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
Integer sum = inp.nextInt();
for(int num = 10000; num < 100000; num++) {
Integer num1 = num / 10000;
Integer num2 = num / 1000 % 10;
Integer num3 = num / 100 % 10;
Integer num4 = num / 10 % 10;
Integer num5 = num % 10;
if(num1 == num5 && num2 == num4 && num1 + num2 + num3 + num4 + num5 == sum) {
System.out.println(num);
}
}
for(int num = 100000; num < 1000000; num++) {
Integer num1 = num / 100000;
Integer num2 = num / 10000 % 10;
Integer num3 = num / 1000 % 10;
Integer num4 = num / 100 % 10;
Integer num5 = num / 10 % 10;
Integer num6 = num % 10;
if(num1 == num6 && num2 == num5 && num3 == num4 && num1 + num2 + num3 + num4 + num5 + num6== sum) {
System.out.println(num);
}
}
}
}