当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
- Flink's sink: a preliminary study
- What can your cloud server do? What is the purpose of cloud server?
- 在51CTO学院Get到PMP证书
- OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- This year's salary is 35W +! Why is the salary of Internet companies getting higher and higher?
- Istio流量管理--Ingress Gateway
- svg究竟是什么?
- Python Gadgets: code conversion
猜你喜欢
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Analysis of istio access control
What can your cloud server do? What is the purpose of cloud server?
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
Flink's sink: a preliminary study
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
[Python 1-6] Python tutorial 1 -- number
Flink从入门到真香(6、Flink实现UDF函数-实现更细粒度的控制流)
第二次作业
值得一看!EMR弹性低成本离线大数据分析最佳实践(附网盘链接)
随机推荐
STM32CubeIDE下载安装-GPIO基本配置操作-Debug调试(基于CMSIS DAP Debug)
Written interview questions: find the smallest positive integer missing
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Windows10关机问题----只有“睡眠”、“更新并重启”、“更新并关机”,但是又不想更新,解决办法
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
C语言I博客作业03
AQS解析
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]
Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
This time Kwai tiktok is faster than shaking.
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Eight ways to optimize if else code
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Flink from introduction to Zhenxiang (7. Sink data output file)
Flink: from introduction to Zhenxiang (6. Flink implements UDF function - realizes more fine-grained control flow)
Python基础语法
吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)
Xamarin deploys IOS from scratch Walterlv.CloudKeyboard application
Q & A and book giving activities of harbor project experts
[Python 1-6] Python tutorial 1 -- number