1006: Steam bottle time limit: 1 sec memory limit: 128 MB
Submitted: 3 solution: 3
[Submit] [Status] [discussion version] Description
There is such a smart question: "A store stipulates that three empty water bottles can be changed to a bottle of soda. John has ten empty water bottles on her hand. How many bottles of soda can she change ?" The answer is 5 bottles. The method is as follows: first use 9 empty bottles for 3 bottles of soda, drink 3 full bottles, and then use 3 to replace 4 empty bottles after drinking, the bottle is full, and there are 2 empty bottles at this time. Then, you ask the boss to lend you a bottle of soda first. After drinking the bottle, use three empty bottles for another full bottle and return it to the boss. If John hasNHow many bottles of soda can I use for empty water bottles?
Input
The input file contains up to 10 groups of test data. Each Data occupies one row and only contains one positive integer.N(1 <=N<= 100), indicating the number of empty steam bottles on the hand of Mr. Zhang.N= 0 indicates that the input is over. Your program should not process this line.
Output
For each group of test data, one line is output, indicating the maximum number of steam bottles that can be consumed. If you cannot drink a bottle, the output is 0.
Input and Output sample input
3
10
81
0
Sample output
1
5
40
Prompt Source
Hunan sixth College Computer Program Design Competition
I haven't asked questions for a long time. The idea of such a simple water question is not very clear at the beginning, and some details are not handled properly. This question is divided by 3 for the number given, the remainder + operator is greater than or equal to 2; it is almost the same to understand the sample 10, handling several special examples; note that the last two empty bottles can also change to a bottle of soda;
Below is the code
#include <cstdio>int main(){ int n,temp; while(scanf("%d",&n)&&n!=0) { int sum=0; while(n>=3) { sum+=n/3; temp=n%3; n/=3; n=temp+n; } if(n==2) sum++; printf("%d\n",sum); } return 0;}Our school also has its own OJ ~