华为编程题汽水瓶
C++答案
#include<iostream>
using namespace std;
int total = 0;
int bottle(int n)
{
int a, b;
a = n / 3;
b = n % 3;
total += a;
if ((a +b) <3)
{
if ((b+a )== 2)
{
total += 1;
}
}
else
{
bottle(a+b);
}
return total;
}
int main()
{
int N;
while (cin >> N)
{
cout << bottle(N)<<endl;
total = 0;
}
system("pause");
return 0;
}