题解 | 汽水瓶
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
#include <iostream>
using namespace std;
int drink(int bottle){
if(bottle < 2)
return 0;
if(bottle == 2)
return 1;
int res = bottle / 3;
return res + drink(res + bottle%3);
}
int main() {
int bottle = 0;
while (cin>>bottle&&bottle != 0) {
cout<<drink(bottle)<<endl;
}
}
// 64 位输出请用 printf("%lld")
查看6道真题和解析