有这样一道智力题,某商店规定三个空瓶换一个汽水‘。。。

题如下图,

代码如下:

#include<iostream>
using namespace std;
int main()
{
	int n;
	while (cin >> n)
	{
		int i = 0;
		while (n != 1 && n != 0)
		{
			i = n / 3+i;
			n = n % 3 + n/3;
			if (n == 2)
			{
				i++;
				n = 0;
			}
		}
		cout << i << endl;
	}
}

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐