Skip to content

Commit 8a61f2f

Browse files
authored
ReturnMoney.java
1 parent 4781f72 commit 8a61f2f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

ReturnMoney.java

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
/**
3+
*
4+
* @author julien
5+
*/
6+
public class ReturnMoney {
7+
8+
int[][] ascTable;
9+
10+
public static void returnMoney(int N, int[] cent, int[] ascArr) {
11+
for (int k : cent) {
12+
for (int i = 0; i <= N - k; i++) {
13+
ascArr[i+k] += ascArr[i];
14+
}
15+
}
16+
}
17+
18+
public static void main(String[] args) {
19+
20+
21+
if (args.length < 2) {
22+
System.out.println("Usage: java ReturnMoney N cent[0] cent[1] cent[2] ...");
23+
System.exit(0);
24+
};
25+
26+
int[] cent = new int[args.length-1];
27+
int N = Integer.parseInt(args[0]);
28+
29+
for (int i = 1; i < args.length; i++) {
30+
cent[i-1] = Integer.parseInt(args[i]);
31+
}
32+
33+
int[] ascArr = new int[N+1];
34+
//Arrays.fill(ascArr, 0);
35+
ascArr[0] = 1;
36+
returnMoney(N, cent, ascArr);
37+
System.out.format("Number of ways of returning change is %d\n", ascArr[N]);
38+
}
39+
}

0 commit comments

Comments
 (0)