-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay4.java
46 lines (44 loc) · 1.22 KB
/
Day4.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public class Lemonade {
public static void sort(int[] array, int n) {
int temp = 0;
for(int i=0; i < n; i++) {
for(int j=1; j < (n-i); j++) {
if(array[j-1] > array[j]) {
temp = array[j-1];
array[j-1] = array[j];
array[j] = temp;
}
}
}
}
public static boolean change(int[] bills, int n) {
int fives = 0, tens = 0;
for (int i = 0; i < n; i++) {
if (bills[i] == 5) {
fives++;
} else if (bills[i] == 10) {
if (fives == 0) {
return false;
}
fives--;
tens++;
} else {
if (tens > 0 && fives > 0) {
tens--;
fives--;
} else if (fives > 2) {
fives -= 3;
} else {
return false;
}
}
}
return true;
}
public static void main(String[] args) {
int n = 5;
int[] bills = {10, 5, 5, 20, 5};
sort(bills, n);
System.out.println(change(bills, n));
}
}