题目链接:汽水瓶_牛客题霸_牛客网
注意点:
当矿泉水瓶剩余2瓶的时候,就可以借一瓶了
#include<iostream>
using namespace std;
int main()
{
//剩余矿泉水瓶res,可以兑换的量为num
int num,res ;
while (cin >> num && num != 0)
{
//每次必须设0,不然会累计
res = 0;
while (num >= 3)
{
res += num / 3;
num = num % 3 + (num / 3) ;
}
if (num == 2) res+=1;
cout << res <<endl;
}
return 0;
}