开心一下-换汽水问题
2017-11-28 01:17
155 查看
一个锻炼脑力的脑筋急转弯
要点:分析出循环条件
实验现象预设:
10块买5瓶汽水,5瓶汽水5个盖子5个空瓶。。。 好麻烦,写个程序吧
要点:分析出循环条件
#include <iostream> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int bottle=0,bottle_cap=0,empty_bottle=0; int num=0,money=0; printf("Please input your money :\n"); while(scanf("%d",&money)==1) { printf("Now the money you have is %d $!\n",money); bottle = money/2; int temp=0,temp_cap=0,temp_empty=0; bottle_cap = bottle;//5个盖 empty_bottle = bottle;//5个瓶子 num += bottle;//喝了5瓶 while(bottle_cap/4 >0 || empty_bottle/2>0) { //处理瓶盖 bottle_cap temp_cap += bottle_cap/4; bottle_cap=bottle_cap%4; temp_empty += empty_bottle/2; empty_bottle=empty_bottle%2; temp = (temp_empty+temp_cap); num += temp; empty_bottle += temp; bottle_cap += temp; temp_cap = 0; temp_empty = 0; temp=0; } printf("According to your money...\n"); printf("you can buy %d bottles'drink\n",num); num = 0; } return 0; }
实验现象预设:
相关文章推荐
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 【区间问题】 hiho一下第152周 - 区间求差
- 随意记录一下RetinaMacbook上PD12虚拟机装ubuntu14.04分辨率问题
- 回复 "刘那" 的问题: 你的例子挺好玩的, 我模拟做了一下
- IE8浏览器访问百度首页,输入关键字,点击“百度一下”,搜索内容出现在一个自动打开的新窗口的问题的一个原因
- 说一下视频播放跟随屏幕旋转,以及activity涉及到的周期问题
- 就mysql command line client刚输入密码立马闪一下退出问题的解决方案
- 昨天花了一下午的时间,终于搞定了sed多行的问题,开心!
- 太逗了··大家也来开心一下··
- 移动支付遇到的一些问题汇总一下
- android webview加载网页按后退键黑屏一下问题的解决方案
- 整理一下遇到过的一些问题