Lanqiao Cup Test Questions--Special Palindrome Numbers for Basic Exercises

The number of special palindromes for basic exercises

Resource limit time limit: 1.0s memory limit: 512.0MB

Problem description 123321 is a very special number, it reads from the left and reads from the right is the same. Enter a positive integer n, and
program to find all such five-digit and six-digit decimal numbers so that the sum of the digits is equal to n.

Input format   
input line, contains a positive integer n.
Output format   
in order from small to large outputs an integer satisfying the condition, each integer per line.

Sample input
52
Sample output
899998
989989
998899

Data scale and convention  
1<=n<=54.

import java.util.*;
public class Main {
    
    
public static void main(String[]args) {
    
    
	Scanner reader=new Scanner(System.in);
	int sum=reader.nextInt();
	for(int i=10000;i<=999999;i++) {
    
    
		if(i>=10000 && i<=99999) {
    
    
			int gewei5=i%10;
			int shiweiwei5=(i % 100) / 10;
			int baiwei5=(i/100)%10;
			int qianwei5=(i / 1000) % 10;
			int wangwei5=i / 10000;
			if((gewei5==wangwei5) &&(shiweiwei5==qianwei5) &&
					(gewei5+shiweiwei5+baiwei5+qianwei5+wangwei5==sum)) {
    
    
				System.out.println(i);
			}
		}
		else {
    
    
			int gewei6=i%10;
			int shiweiwei6=(i % 100) / 10;
			int baiwei6=(i%1000)/100;
			int qianwei6=(i/1000)%10;
			int wangwei6=(i/10000)%10;
			int shiwanwei6=i / 100000;
			if((gewei6==shiwanwei6)&&(shiweiwei6==wangwei6)&&(baiwei6==qianwei6)&&
					(gewei6+shiweiwei6+baiwei6+qianwei6+wangwei6+shiwanwei6==sum)) {
    
    
				System.out.println(i);
			}
		}
	}
}
}

Guess you like

Origin blog.csdn.net/TroyeSivanlp/article/details/108653174