3个空瓶换一瓶新酒的小问题

题目:共有1000瓶啤酒,每喝完一瓶得到一个空瓶子,每3个空瓶子又能换1瓶啤酒,喝掉以后又可以得到一个空瓶子,问总共能喝到多少瓶啤酒,最后还剩余多少个空瓶子?

用C++简单写了一个:

#pragma region Quiz requirements
// The Quiz is to calculate the number of bottles:
// There are 1000 bottles of beer, 3 empty bottles can 
// trade for another additional beer
// How many bottles will it be and how many empty
// bottles will be left?
#pragma endregion
#include <iostream>
using std::cout;
using std::endl;

int main()
{
	int total = 1000;
	int full = 1000;
	int empty = 0;
	for(full=1000; full >0 ; full--) 
		// stop until you finish every full beer bottle available
	{
		++ empty;
		if(empty == 3)
		{
			empty = 0;
			++ full;
			++ total;
		}
	}
	cout << "Total number of bottle is: " << total << endl;
	cout << "Total empty bottle left is: " << empty << endl;
	return 0;
}


 最的的结果如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值