oj1663: soda bottles

Topics requirements
there is such a puzzle: "a store states: three empty soda bottles for a bottle of soda Zhang can have ten empty soda bottles on hand, she can change how many bottles of soda up to drink.?" The answer is five bottles, as follows: the first for 3 bottles of soda with nine empty bottles, drink bottles 3 full, empty bottles after drinking 4, with the bottle 3 and back, this drink bottle is full, and this time left empty 2 bottle. Then you let the boss to lend you a bottle of soda, drink this bottle full, after drinking for a bottle filled with three empty bottles back to the boss. If there are n the hands of Zhang empty soda bottles, soda bottles can change the maximum number of drink?
Input
Input file contains up to 10 test cases, each data per line, comprising only a positive integer n (1 <= n <= 100), indicates the number of empty bottle vapor Zhang hand. n = 0 indicates the end of input, your program should not deal with this line.
Output
For each test, an output line, represents the bottle up to drink. If you drink a bottle of less than 0 is output.
The Input the Sample
Raw
3
10
81
0
the Sample the Output
Raw
1
5
40
The idea is simple, a pile of empty bottles minus 3, plus one full bottle, empty bottle known as the 2:00 can borrow a boss, plus a full bottle last.

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	int n,m;
	while(cin>>m)
	{
		n=0;
		if(m==0)break;
		while (m - 3 >= 0)
		{
			m = (m - 3) + 1;
			n++;
		}
		if (2 == m)
			n = n + 1;
		cout<<n<<endl;
	}
	return 0;
}
Published 38 original articles · won praise 27 · views 3179

Guess you like

Origin blog.csdn.net/qq_45891413/article/details/105018892