当前位置:网站首页>喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
2020-11-08 12:56:00 【osc_51airx3z】
第一种方法
#include<stdio.h>
#include<Windows.h>
#pragma warning(disable:4996)
int Qishui(int n)
{
int total = 0;
total += n;
for (; n >= 2;n=n/2+n%2)
{
total += n / 2;
}
return total;
}
int main()
{
int money = 0;
printf("你有多少钱:");
scanf_s("%d", &money);
int ret = Qishui(money);
printf("可以买%d瓶汽水\n", ret);
system("pause");
return 0;
}
第二种方法
#include<stdio.h>
#include<Windows.h>
#pragma warning(disable:4996)
int Qishui(int money)
{
int total = money;
int empty = money;
while (empty > 1)
{
total += empty / 2;
empty = empty / 2 + empty % 2;
}
return total;
}
int main()
{
int money = 0;
printf("你有多少钱:");
scanf_s("%d", &money);
int ret = Qishui(money);
printf("可以买%d瓶汽水\n", ret);
system("pause");
return 0;
}
版权声明
本文为[osc_51airx3z]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4263556/blog/4708158
边栏推荐
- STM32CubeIDE下载安装-GPIO基本配置操作-Debug调试(基于CMSIS DAP Debug)
- 一文读懂机器学习“数据中毒”
- 阿里教你深入浅出玩转物联网平台!(附网盘链接)
- Xamarin deploys IOS from scratch Walterlv.CloudKeyboard application
- From a friend recently Ali, Tencent, meituan and other P7 Python development post interview questions
- python小工具:编码转换
- Flink: from introduction to Zhenxiang (3. Reading data from collection and file)
- 在51CTO学院Get到PMP证书
- 华为云重大变革:Cloud&AI 升至华为第四大 BG ,火力全开
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
猜你喜欢
Get PMP certificate at 51CTO College
Flink从入门到真香(7、Sink数据输出-文件)
Tidb performance competition 11.02-11.06
分布式文档存储数据库之MongoDB基础入门
The young generation of winner's programming life, the starting point of changing the world is hidden around
维图PDMS切图软件
适合c/c++新手学习的一些项目,别给我错过了!
Flink from introduction to Zhenxiang (7. Sink data output file)
How to deploy pytorch lightning model to production
Adobe media encoder /Me 2021软件安装包(附安装教程)
随机推荐
笔试面试题目:判断单链表是否有环
吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)
Written interview questions: find the smallest positive integer missing
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
Flink从入门到真香(7、Sink数据输出-文件)
分布式文档存储数据库之MongoDB基础入门
Adobe Lightroom /Lr 2021软件安装包(附安装教程)
值得一看!EMR弹性低成本离线大数据分析最佳实践(附网盘链接)
STM32CubeIDE下载安装-GPIO基本配置操作-Debug调试(基于CMSIS DAP Debug)
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
211考研失败后,熬夜了两个月拿下字节offer!【面经分享】
学习小结(关于深度学习、视觉和学习体会)
Personal current technology stack
11 server monitoring tools commonly used by operation and maintenance personnel
适合c/c++新手学习的一些项目,别给我错过了!
Q & A and book giving activities of harbor project experts
Python Gadgets: code conversion
This time Kwai tiktok is faster than shaking.
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
YGC问题排查,又让我涨姿势了!