本帖最后由 葬礼昨天 于 2017-10-18 15:32 编辑
[C] 纯文本查看 复制代码 #include<stdio.h>
int main()
{
int i, btle=0, tap=0, num, n, iTemp; //btle是瓶子,tap是瓶盖(忘了瓶盖是哪个单词了)。。
printf("please input the money:\n");
scanf("%d", &n);
num = n/2;
btle = n/2;
tap = n/2;
n /= 2;
while((btle>=2) || (tap>=4))
{
if(btle>=2)
{
if(0==btle%2)
{
num += btle/2;
tap += btle/2;
btle /= 2;
}
else if(1==btle%2)
{
btle--;
num += btle/2;
tap += btle/2;
btle /= 2;
btle++;
}
}
if(tap>=4)
{
if(0==tap%4)
{
num += tap/4;
btle += tap/4;
tap /=4;
}
else if(tap%4)
{
iTemp = tap%4;
num += tap/4;
btle += tap/4;
tap /=4;
tap += iTemp;
}
}
}
printf("you will drink %d bottles beer!\n", num);
return 0;
}
在骑去百科上看到的,就编程实现了下,虽然我知道这个程序真的很简单,但还是很高兴能编出来,小菜鸟一直,希望懂的人能提些意见以此提高,不尽感激! |