50,528
社区成员
发帖
与我相关
我的任务
分享
public class Sample {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int elem[] = new int[10]; //每种原子的个数
Arrays.fill(elem, 1);
int max = n/10 + 1;
List<String> result = new ArrayList<>();
while(elem[0]<=max) {
int sum = 0;
for(int i=0; i<10; i++) sum += elem[i]; //原子总个数
if (sum==n) { //原子总个数和n相等则保存结果
result.add(Arrays.toString(elem).replaceAll("[\\[\\],]", ""));
}
elem[9]++; //原子总个数变化
for(int i=9; i>0; i--) {
if (elem[i]>max) {
elem[i-1]++;
elem[i] = 1;
}
}
}
System.out.println(result.size());
for (String s : result) {
System.out.println(s);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}