描述 | |
---|---|
知识点 | 循环 |
运行时间限制 | 0M |
内存限制 | 0 |
输入 | 输入文件最多包含10组测试数据,每个数据占一行,仅包含一个正整数n(1<=n<=100),表示小张手上的空汽水瓶数。n=0表示输入结束,你的程序不应当处理这一行。 |
输出 | 对于每组测试数据,输出一行,表示最多可以喝的汽水瓶数。如果一瓶也喝不到,输出0。 |
样例输入 | 3 10 81 0 |
样例输出 | 1 5 40 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
//#include "Customer.h"
using namespace std;
int getCount(int n)
{
int count = 0;
int empty = n;
while (empty > 1)
{
if (empty == 4)
{
count += 2;
break;
}
if (empty == 2)
{
count++;
break;
}
n = empty / 3;
count += n;
empty = empty % 3 + n;
}
return count;
}
int main()
{
int n;
while (cin >> n)
{
if (n == 0)
break;
cout << getCount(n) << endl;
}
return 0;
}