-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemptyBottle.java
More file actions
46 lines (46 loc) · 1.11 KB
/
emptyBottle.java
File metadata and controls
46 lines (46 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
import java.util.Scanner;
public class Main{
public static void main(String[] args)
{
Scanner sc =new Scanner(System.in);
Main main =new Main();
while(sc.hasNext())
{
int num = sc.nextInt();
if(num==0) break;
System.out.println(main.waterBottle(num));
}
}
public int waterBottle(int n)
{
int res=0;
while(n/3>0)
{
res=res+n/3;
n=n/3+n%3;
}
return res=n==2?res+1:res;
}
/* {
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
int num = sc.nextInt();
if(num==0) break;
int left = num;
int total = 0;
while(left!=0){
if(left==2){
total+=1;
break;
}else if(left==1){
break;
}else{
int curr = left/3;
total+=curr;
left = left-curr*3+curr;
}
}
System.out.println(total);
}*/
}