题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
欢迎大家来优化一下,我觉得我写得很暴力
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int EmptyBottle;
int ColaDrink;
out:while (sc.hasNext()) {
EmptyBottle = Integer.parseInt(sc.nextLine());
ColaDrink=0;
if (EmptyBottle == 0) {
break out;
}
do {
if (EmptyBottle >=3) {
ColaDrink += EmptyBottle / 3;
EmptyBottle=EmptyBottle/3+EmptyBottle%3;
}
if (EmptyBottle == 2) {
ColaDrink++;
EmptyBottle=0;
break ;
}
//下面这句可以没有
if (EmptyBottle==1){
ColaDrink+=0;
}
} while (EmptyBottle != 1);
System.out.println(ColaDrink);
}
}
}
ColaDrink+=0;
}
} while (EmptyBottle != 1);
System.out.println(ColaDrink);
}
}
}