-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoinCalculator.java
More file actions
66 lines (65 loc) · 1.11 KB
/
CoinCalculator.java
File metadata and controls
66 lines (65 loc) · 1.11 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package codechef;
import java.io.*;
import java.util.*;
public class CoinCalculator {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
coinCal(n);
}
public static void coinCal(int n){
int a = 1;
int b = 1;
int c = 1;
int d = 1;
int diff = n;
int n1 = 0;
while(diff>=a*5){
++a;
n1 += 5;
}
diff = n-n1;
if(diff!=0){
System.out.println(a-1);
}
else{
System.out.println(a-1);
System.out.println("0");
System.out.println("0");
System.out.println("0");
return;
}
while(diff>=b*3){
++b;
n1 += 3;
}
diff = n - n1;
if(diff!=0){
System.out.println(b-1);
}else{
System.out.println(b-1);
System.out.println("0");
System.out.println("0");
return;
}
while(diff>=c*2){
++c;
n1 += 2;
}
diff = n - n1;
if(diff!=0){
System.out.println(c-1);
}
else{
System.out.println(c-1);
System.out.println("0");
return;
}
while(diff>=d*1){
++d;
n1++;
}
diff = n-n1;
System.out.println(d-1);
}
}