开心一下-换汽水问题
2017-11-28 01:17
211 查看
一个锻炼脑力的脑筋急转弯
要点:分析出循环条件
实验现象预设:
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; }
实验现象预设:
相关文章推荐
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 开心一下-换汽水问题
- 总结一下PHP扩展开发中遇到的问题
- 关于即时通讯协议设计的问题 望和大家讨论一下
- 军方让我做即时通讯,好好交代一下网络安全问题(附源码)
- 记录一下关于IntelliJ IDEA 及部分使用问题
- 简单问题,解决了也开心
- 记录一下 关于进程隐藏摘链操作的问题
- android 解决fragment中有百度高德等地图,切换出现闪一下黑屏的问题
- 自学了三天的SeaJs学习,解决了前端的一些问题,与小伙伴们一起分享一下!
- 手机响一下,挂断问题
- 背包问题先记录一下
- 解决Fragment中使用地图,切换会闪一下黑屏的问题