小明喝酒的问题

题目描述:

小明带20块钱去喝酒,啤酒两块钱一瓶,两个瓶可以换一瓶酒,四个瓶盖可以换一瓶酒,问小明总共能喝几瓶酒?

 

代码如下

 1 /*
 2 * @Author: Shuai
 3 * @Date:   2016-04-14 20:40:40
 4 * @Last Modified by:   Shuai
 5 * @Last Modified time: 2016-04-14 22:25:24
 6 */
 7 /*
 8 * @Author: Shuai
 9 * @Date:   2016-04-14 20:40:40
10 * @Last Modified by:   Shuai
11 * @Last Modified time: 2016-04-14 20:47:10
12 */
13 
14 #include <stdio.h>
15 #define money 20
16 int main() {
17     int jiu = money/2;//
18     int ping=jiu;//剩的瓶
19     int gai=jiu;//剩的盖子
20 
21     for(;;){
22         if (ping>1){//换了喝
23             jiu = ping/2 + jiu;
24             gai =ping/2+gai; 
25             ping=ping%2+ping/2;
26         }
27         if (gai>3){//换了喝
28             jiu = gai/4 + jiu;
29             ping =gai/4+ping;
30             gai = gai%4+gai/4; 
31         }
32         printf("酒 %d  瓶 %d  盖 %d\n", jiu, ping, gai);
33 
34         if (ping<2 && gai<4){
35             printf("===酒 %d  瓶 %d  盖 %d===\n", jiu, ping, gai);
36             break;            
37         }
38     }
39 
40     return 0;
41 }

posted @ 2016-04-14 22:28  一支小白  阅读(440)  评论(0编辑  收藏  举报