关于一个算法题的想法:1000瓶汽水,每喝3瓶赚一瓶,最终喝了多少瓶,剩几个空瓶?

//1000 bottles issues

#include

<stdio.h>

void

Bottle(int,int);

void

Media(int, int);

int

total;

void

main(int argc, char* argv[])

{

Media(1000,3);

}

void

Media(int remain, intn)

{

total = remain;

Bottle(remain, n);

}

void

Bottle(int remain, intn)

{

if(remain < n)

{

printf(

"Remain:%d,Total:%d", remain,total);

}

else

{

total += remain/n;

Bottle(remain/n+remain%n, n);

}

}

posted on 2011-09-21 10:49  影一辉  阅读(245)  评论(0编辑  收藏  举报