题解 | #汽水瓶#
汽水瓶
http://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
汽水瓶:C语言解法
利用递归的思想去循环兑换汽水
#include<stdio.h>
int conversion(int bottle){
if(bottle == 1){
return 0;
}else if(bottle == 2){//从老板那借一瓶
return 1;
}else{
return bottle/3+conversion(bottle/3+bottle%3);
}
}
int main(){
int bottle = 0;
while(~scanf("%d\n",&bottle)){
if(bottle == 0) continue;
printf("%d\n",conversion(bottle));
}
}