62,625
社区成员
发帖
与我相关
我的任务
分享

谁有2元的RMB给我开开眼public class Main {
public static void main(String[] args) {
String[] moneynum = { "100", "50", "20", "10", "5", "2", "1" };
String[] result = new String[moneynum.length];
Main.pailie(moneynum, result, 0);
}
private static String[] pailie(String[] moneynum, String[] result, int length) {
if (moneynum.length != 0) {
List<String> list = new ArrayList<String>();
for (int i = 0; i < moneynum.length; i++) {
list.clear();
list = Main.add(moneynum);
result[length] = moneynum[i];
list.remove(moneynum[i]);
String[] arr = list.toArray(new String[moneynum.length - 1]);
Main.pailie(arr, result, length + 1);
}
} else {
Main.print(result);
}
return null;
}
private static List add(String [] s){
List<String> list = new ArrayList<String>();
for(String a : s){
list.add(a);
}
return list;
}
private static void print(String[] result) {
for (int i = 0; i < result.length; i++) {
System.out.print(result[i] + ", ");
}
System.out.println();
}
}

public class Test{
public static void main(String[] args){
String[] strs = {"a","b","c","d"};
sort(strs);
}
private static void sort(String[] strs){
sort(strs,0);
}
private static void sort(String[] strs,int index){
if(index == strs.length){
for(String str : strs){
System.out.printf("%s ",str);
}
System.out.println();
return;
}
String temp = null;
for(int i = index ; i < strs.length ; i ++){
temp = strs[i];
strs[i] = strs[index];
strs[index] = temp;
sort(strs,index + 1);
temp = strs[i];
strs[i] = strs[index];
strs[index] = temp;
}
}
}
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.close();
List<String> result = new ArrayList<>();
int max100 = n / 100;
for (int i100 = 0; i100 <= max100; i100++) {
int max50 = (n - i100 * 100) / 50;
for (int i50 = 0; i50 <= max50; i50++) {
int max20 = (n - i100 * 100 - i50 * 50) / 20;
for (int i20 = 0; i20 <= max20; i20++) {
int max10 = (n - i100 * 100 - i50 * 50 - i20 * 20) / 10;
for (int i10 = 0; i10 <= max10; i10++) {
int max5 = (n - i100 * 100 - i50 * 50 - i20 * 20 - i10 * 10) / 5;
for (int i5 = 0; i5 <= max5; i5++) {
int max2 = (n - i100 * 100 - i50 * 50 - i20 * 20 - i10 * 10 - i5* 5) / 2;
for (int i2 = 0; i2 <= max2; i2++) {
int max1 = n - i100 * 100 - i50 * 50 - i20 * 20 - i10 * 10 - i5* 5 - i2* 2;
for (int i1 = 0; i1 <= max1; i1++) {
if (100 * i100
+ 50 * i50
+ 20 * i20
+ 10 * i10
+ 5 * i5
+ 2 * i2
+ 1 * i1 == n) {
String str = String.format("100 * %d "
+ "+ 50 * %d + 20 * %d + 10 * %d "
+ "+ 5 * %d + 2 * %d + 1 * %d",
i100, i50, i20, i10, i5, i2, i1);
result.add(str);
}
}
}
}
}
}
}
}
System.out.println("count:");
System.out.println(result.size());
System.out.println("combination:");
Iterator<String> iter = result.iterator();
while (iter.hasNext()) {
System.out.println(iter.next());
}
}
}
