关于一个算法题的想法: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);
}
}