当前位置:网站首页>Drink soda, a bottle of soda water 1 yuan, two empty bottles can change a bottle of soda, give 20 yuan, how much soda can you
Drink soda, a bottle of soda water 1 yuan, two empty bottles can change a bottle of soda, give 20 yuan, how much soda can you
2020-11-08 12:56:00 【open_51airx3z】
The first method
#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(" How much money do you have? :");
scanf_s("%d", &money);
int ret = Qishui(money);
printf(" Can buy %d Bottle of soda \n", ret);
system("pause");
return 0;
}
The second method
#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(" How much money do you have? :");
scanf_s("%d", &money);
int ret = Qishui(money);
printf(" Can buy %d Bottle of soda \n", ret);
system("pause");
return 0;
}
版权声明
本文为[open_51airx3z]所创,转载请带上原文链接,感谢
边栏推荐
- 这次,快手终于比抖音'快'了!
- 阿里出品!视觉计算开发者系列手册(附网盘链接)
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- How to solve the difference between NAT IP and port IP
- Flink从入门到真香(3、从集合和文件中读取数据)
- Windows10关机问题----只有“睡眠”、“更新并重启”、“更新并关机”,但是又不想更新,解决办法
- TiDB 性能竞赛 11.02-11.06
- Entry level! Teach you how to develop small programs without asking for help (with internet disk link)
- Get PMP certificate at 51CTO College
- STM32CubeIDE下载安装-GPIO基本配置操作-Debug调试(基于CMSIS DAP Debug)
猜你喜欢
分布式文档存储数据库之MongoDB基础入门
适合c/c++新手学习的一些项目,别给我错过了!
Adobe Lightroom / LR 2021 software installation package (with installation tutorial)
浅谈单调栈
在51CTO学院Get到PMP证书
python基础教程python opencv pytesseract 验证码识别的实现
The progress bar written in Python is so wonderful~
这次,快手终于比抖音'快'了!
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
PMP experience sharing
随机推荐
原创 | 数据资产确权浅议
C language I blog assignment 03
AQS analysis
The container with the most water
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Why is Schnorr Signature known as the biggest technology update after bitcoin segwit
一个方案提升Flutter内存利用率
On monotonous stack
Entry level! Teach you how to develop small programs without asking for help (with internet disk link)
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
阿里教你深入浅出玩转物联网平台!(附网盘链接)
蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
Windows10关机问题----只有“睡眠”、“更新并重启”、“更新并关机”,但是又不想更新,解决办法
On the software of express delivery cabinet and deposit cabinet under Windows
谷歌开源能翻译101种语言的AI模型,只比Facebook多一种
Adobe Lightroom /Lr 2021软件安装包(附安装教程)