蓝桥杯特殊回文数附带代码(JAVA实现)
`import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;
public class Main
{
static TreeSet arrayList;
public static void main(String[] args)
{
arrayList = new TreeSet<>();
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
sc.close();
out_answer(a);
}
private static void out_answer(int n)
{
int[] b = new int[6];
for (int i = 99; i <1000 ; i ++) {
int j = i;
int index = 2 ;
int sum =0;
while(j > 0)
{
sum = sum + j%10;
b[index] = j%10;
j = j/10;
index --;
}
if(b[0] != 0 )
{
if(sum * 2 == n )
{
double sum1 = 0;
for (int k = 3,l=2; k <6 ; k++,l--) {
b[k] = b[l];
}
for (int k = 0; k < 6; k++) {
sum1= sum1 + b[k]*Math.pow(10,k);
}
arrayList.add((int)sum1);
}
if((n - (b[0] + b[1]) * 2) < 10 && (n - (b[0] + b[1]) * 2) >= 0)
{
double sum1 = 0;
b[2] = n - (b[0] + b[1]) * 2;
for (int k = 3,l=1; k < 5 ; k++,l--) {
b[k] = b[l];
}
for (int k = 0; k < 5; k++) {
sum1= sum1+ b[k]*Math.pow(10,k);
}
arrayList.add((int)sum1);
}
}
}
for(Integer demo: arrayList)
{
System.out.println(demo);
}
}
}`