資源限制
時間限制:1.0s 內存限制:512.0MB
問題描述
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 sc = new Scanner(System.in);
int key = sc.nextInt() ;
for( int i = 10000 ; i < 1000000 ; i++ ) {
int a = i%10 ; //個位數
int b = i/10%10 ;//十位數
int c = i/100%10 ;
int d = i/1000%10 ;
int e = i/10000%10 ;//萬位數
int f = i/100000%10 ;
if(i<100000) {
if(a == e && b == d && a+b+c+d+e == key )
System.out.println(i);
}
else {
if(a == f && b == e && c == d && a+b+c+d+e+f == key )
System.out.println(i);
}
}
}
}