题解 | #汽水瓶#
汽水瓶
http://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
-
不要在意变量名
-
要有3个变量 喝的瓶数是在变的,所以,需要另一个变量来记录最终喝的多少,还要记录空瓶数
-
不足之处请给与指正
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
ArrayList<Integer> result = new ArrayList<>();
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
int he = 0;
int resulthe =0;
int kong = sc.nextInt();
if(kong ==0){
break;
}else {
while (kong >=3){
he = kong/3;
kong = kong%3 + he;
resulthe += he;
if(kong ==2){
resulthe +=1;
}
}
result.add(resulthe);
}
}
Iterator<Integer> it = result.iterator();
while (it.hasNext()){
System.out.println(it.next());
}
}
}