package oj.test;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
/*
有这样一道智力题:“某商店规定:三个空汽水瓶可以换一瓶汽水。小张手上有十个空汽水瓶,她最多可以换多少瓶汽水喝?”答案是5瓶,方法如下:先用9个空瓶子换3瓶汽水,喝掉3瓶满的,喝完以后4个空瓶子,用3个再换一瓶,喝掉这瓶满的,这时候剩2个空瓶子。然后你让老板先借给你一瓶汽水,喝掉这瓶满的,喝完以后用3个空瓶子换一瓶满的还给老板。如果小张手上有n个空汽水瓶,最多可以换多少瓶汽水喝?(最后输入0结束输入)
*/
public class Demo1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LinkedList<Integer> link = new LinkedList<Integer>();
while(sc.hasNext() ){
int n = sc.nextInt();
if(n==0)
break;
link.add(n);
}
Iterator<Integer> it = link.iterator();
while(it.hasNext()){
int i = it.next();
//System.out.println(i);
System.out.println(fun(i));
}
}
private static int fun(int i) {
int heidiao=0;
int remain=0;
if(i<=1)
return 0;
if(i==2)
return 1;
heidiao = i/3;
remain = i%3;
return heidiao+fun(heidiao+remain);
}
}