C # Empty water bottle Problems

Source: Internet
Author: User

Problem 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.

Sample Input

3

10

81

0

Sample output

1

5

40

Problem Source

The sixth Hunan Collegiate Programming Contest

[Webmethod] public int nullqiwateping_q (int n) {// 2-> 1 (2/3 =, 0 + 2 = 2, [1] + 2 = 3, 3/3 = 1) // 3-> 1 (3/3 = 1) // 4-> 2 (4/3 =; 1 + 1 = 2, [1] + 2 =/3 = 1) // 5-> 2 (5/3 = 1, 2; 1 + 2 = 3, 3/3 = 1) // 6-> 2 (6/3 = 2) // 7-> 3 (7/3 = 3/3; 2 + 1 = 3; 8/3 = 1) // 8-> 4 (=; 2 + 2 = 4) // 10-> 5 (10/3 = 3, 1; 3/3 = 1; 1 + 1 = 2; 3-2 = 1) int RBC = 0; If (n <1) return RBC; If (n = 2) return 1; int z = N/3; // integer part int y = n % 3; // If (Z = 0) return Z; return Z + nullqiwateping_q (Z + Y);} [webmethod] public void nullqiwateping_q_loop () {for (INT I = 0; I <100; I ++) {This. context. response. write (I. tostring () + "=" + nullqiwateping_q (I ). tostring () + "<br> ");}}

Result:

Number of empty water bottles = number of drinking water bottles

0 = 0
1 = 0
2 = 1
3 = 1
4 = 2
5 = 2
6 = 3
7 = 3
8 = 4
9 = 4
10 = 5
11 = 5
12 = 6
13 = 6
14 = 7
15 = 7
16 = 8
17 = 8
18 = 9
19 = 9
20 = 10
21 = 10
22 = 11
23 = 11
24 = 12
25 = 12
26 = 13
27 = 13
28 = 14
29 = 14
30 = 15
31 = 15
32 = 16
33 = 16
34 = 17
35 = 17
36 = 18
37 = 18
38 = 19
39 = 19
40 = 20
41 = 20
42 = 21
43 = 21
44 = 22
45 = 22
46 = 23
47 = 23
48 = 24
49 = 24
50 = 25
51 = 25
52 = 26
53 = 26
54 = 27
55 = 27
56 = 28
57 = 28
58 = 29
59 = 29
60 = 30
61 = 30
62 = 31
63 = 31
64 = 32
65 = 32
66 = 33
67 = 33
68 = 34
69 = 34
70 = 35
71 = 35
72 = 36
73 = 36
74 = 37
75 = 37
76 = 38
77 = 38
78 = 39
79 = 39
80 = 40
81 = 40
82 = 41
83 = 41
84 = 42
85 = 42
86 = 43
87 = 43
88 = 44
89 = 44
90 = 45
91 = 45
92 = 46
93 = 46
94 = 47
95 = 47
96 = 48
97 = 48
98 = 49
99 = 49

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.