#include <stdio.h>
void calTotalNum(int bottleNum, int* totalSodaNum);
int main() {
int n;
int totalSodaNum;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
break;
}
totalSodaNum = 0; // 每次需要重置为 0
calTotalNum(n, &totalSodaNum);
printf("%d\n", totalSodaNum);
}
return 0;
}
// 递归函数,明确退出条件
void calTotalNum(int bottleNum, int* totalSodaNum)
{
int extraSoda = bottleNum / 3; // 兑换后得到的汽水
int extraBottle = bottleNum % 3; // 兑换后剩余的空瓶
int curBottle = extraSoda + extraBottle; // 喝完汽水后的总瓶子
*totalSodaNum += extraSoda;
//printf("--- + %d = %d %d\n", extraSoda, *totalSodaNum, curBottle);
if (curBottle >= 3) {
return calTotalNum(curBottle, totalSodaNum);
}
if (curBottle == 2) {
*totalSodaNum += 1; // 当前有两个瓶子,可以借一个兑换后还一个
// printf("*** + %d = %d\n", 1, *totalSodaNum);
return;
}
if (curBottle == 1) { // 当前有1个瓶子,不能继续兑换
return;
}
}