三九宝宝网宝宝百科宝宝知识

蓝桥杯java试题购物券

01月06日 编辑 39baobao.com

[蓝桥杯往年本科java试题。。]一、单选题目(主要考擦java基础知识 好像25道) 1、String与StringBuffer区别 如: 2、final中的return switch中的break和return 执行的顺序和执行结果 3、for; do...while(); w...+阅读

public class Cal {

private static Integer price[];

private static Integer result[];

private static Integer num;

private static List list = new ArrayList();

public static void main(String[] args) throws Exception {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String numStr = br.readLine();

num = Integer.parseInt(numStr);

if(num==null||num==0) return;

price = new Integer[num];

result = new Integer[num];

for(int i=0; i

result[i] = 0;

}

for(int i=0; i

price[i] = Integer.parseInt(br.readLine());

}

cal(1000, 0);

System.out.println(list.size());

for(Integer[] resu : list){

for(Integer n : resu){

System.out.print(n+" ");

}

System.out.println();

}

}

public static void cal(int money, int i){

if(money<0)return;

if(i>=num)return;

if(money==0){

Integer[] line = new Integer[num];

for (int j = 0; j < line.length; j++) {

line[j] = result[j];

}

list.add(line);

return;

}

for(;i

result[i]++;

cal(money-price[i], i);

result[i]--;

}

}

}

推荐阅读
图文推荐