-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtuenti1.java
More file actions
41 lines (31 loc) · 708 Bytes
/
Copy pathtuenti1.java
File metadata and controls
41 lines (31 loc) · 708 Bytes
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
public class tuenti1 {
/**
* @author Andres Leon Suarez Cetrulo
* Bitcoin buy-sell problem for Tuenti Challenge 3 (2013)
*/
public static void main(String[] args) {
/*eg 1
int saldo = 2;
int bitcoins = 0;
int[] b = {1,2,10,4,1,10};*/
//eg 2
int saldo = 5;
int bitcoins = 0;
int[] b = {1,2,4,20,5,30,4,25,7};
for(int i = 1; i<b.length; i++){
if (b[i]>b[i-1]&&saldo>0){
//buy
bitcoins = saldo/b[i-1];
saldo = 0;
}if(b[i]<b[i-1]&&bitcoins > 0){
//sell
saldo = bitcoins*b[i-1];
bitcoins = 0;
}if(i == b.length-1 && bitcoins > 0){
//sell
saldo = bitcoins*b[i];
bitcoins = 0;
}
} System.out.println(saldo);
}
}