#include "stdafx.h"
const int BOTTLE_COUNT_TO_A_BEER = 2;
const int GAP_COUNT_TO_A_BEER = 4;
const int PRICE_OF_A_BEER = 2;
void get_beer_count(int& beer_count, int& bottle_count, int& gap_count)
{
if (gap_count < GAP_COUNT_TO_A_BEER && bottle_count < BOTTLE_COUNT_TO_A_BEER)
{
return;
}
beer_count += bottle_count/BOTTLE_COUNT_TO_A_BEER;
beer_count += gap_count/GAP_COUNT_TO_A_BEER;
int bottle_count_old = bottle_count;
int gap_count_old = gap_count;
bottle_count = bottle_count_old%BOTTLE_COUNT_TO_A_BEER + bottle_count_old/BOTTLE_COUNT_TO_A_BEER + gap_count_old/GAP_COUNT_TO_A_BEER;
gap_count = gap_count_old%GAP_COUNT_TO_A_BEER + gap_count_old/GAP_COUNT_TO_A_BEER + bottle_count_old/BOTTLE_COUNT_TO_A_BEER;
get_beer_count(beer_count, bottle_count, gap_count);
}
int get_beer_count(int money)
{
int beer_count = money/PRICE_OF_A_BEER;
int bottle_count = beer_count;
int gap_count = bottle_count;
get_beer_count(beer_count, bottle_count, gap_count);
return beer_count;
}
int _tmain(int argc, _TCHAR* argv[])
{
int money = 10;
int beer_count = get_beer_count(money);
return 0;
}
最多能喝多少瓶啤酒呢?
最新推荐文章于 2023-03-14 16:22:46 发布