/*
啤酒
2块1瓶
4个瓶盖换1瓶
2个空瓶换1瓶
问:10元可以喝几瓶
*/
int lefttop,leftbottle;
int main(int argc, const char * argv[]) {
int sum = 5;
int count = drink(5, 5);
printf("总共能喝%d\n剩下的瓶盖:%d\n剩下的空瓶:%d\n",count+sum,lefttop,leftbottle);
return 0;
}
//implicit declaration of funtion is invalid in C99
int drink(int top,int bottle)
{
if(bottle>=2 || top>=4)
{
leftbottle = bottle/2 + bottle%2 + top/4;
lefttop = top/4 + top%4 + bottle/2;
return (bottle/2)+(top/4)+drink(lefttop, leftbottle);
}
return 0;
}