问题描述
123321是一个非常特殊的数,它从左边读和从右边读是一样的。
输入一个正整数n, 编程求所有这样的五位和六位十进制数,满足各位数字之和等于n 。
输入格式
输入一行,包含一个正整数n。
输出格式
按从小到大的顺序输出满足条件的整数,每个整数占一行。
样例输入
52
样例输出
899998
989989
998899
数据规模和约定
1<=n<=54。
import
java.util.Scanner;
public
class
Main
{
public
static
void
main(String[] args)
{
Scanner scanner =
new
Scanner(System.in);
while
(scanner.hasNext())
{
int
n = scanner.nextInt();
for
(
int
i =
10000
; i <=
999999
; i++)
{
char
[] c = String.valueOf(i).toCharArray();
if
(c.length ==
5
)
{
if
(c[
0
] == c[
4
] && c[
1
] == c[
3
])
{
int
sum =
0
;
for
(
int
j =
0
; j < c.length; j++)
{
sum = sum + (
int
)(c[j] -
'0'
);
}
if
(sum == n)
System.out.println(i);
}
}
else
{
if
(c[
0
] == c[
5
] && c[
1
] == c[
4
] && c[
2
] == c[
3
])
{
int
sum =
0
;
for
(
int
j =
0
; j < c.length; j++)
{
sum = sum + (
int
)(c[j] -
'0'
);
}
if
(sum == n)
System.out.println(i);
}
}
}
}
}
}