当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Understanding design patterns
- On the software of express delivery cabinet and deposit cabinet under Windows
- The progress bar written in Python is so wonderful~
- Ali! Visual computing developer's series of manuals (with internet disk link)
- Or talk No.19 | Facebook Dr. Tian Yuandong: black box optimization of hidden action set based on Monte Carlo tree search
- Q & A and book giving activities of harbor project experts
- [Python 1-6] Python tutorial 1 -- number
- android基础-CheckBox(复选框)
- When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)
- 浅谈单调栈
猜你喜欢

分布式文档存储数据库之MongoDB基础入门

阿里撕下电商标签

Adobe media encoder /Me 2021软件安装包(附安装教程)

On the confirmation of original data assets

Get PMP certificate at 51CTO College

吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)

python基础教程python opencv pytesseract 验证码识别的实现

The container with the most water

Written interview questions: find the smallest positive integer missing

TiDB 性能竞赛 11.02-11.06
随机推荐
We interviewed the product manager of SQL server of Alibaba cloud database, and he said that it is enough to understand these four problems
一个方案提升Flutter内存利用率
适合c/c++新手学习的一些项目,别给我错过了!
Istio流量管理--Ingress Gateway
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
用 Python 写出来的进度条,竟如此美妙~
Flink: from introduction to Zhenxiang (6. Flink implements UDF function - realizes more fine-grained control flow)
AQS analysis
C language I blog assignment 03
Flink从入门到真香(10、Sink数据输出-Elasticsearch)
供货紧张!苹果被曝 iPhone 12 电源芯片产能不足
在51CTO学院Get到PMP证书
svg究竟是什么?
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
分布式文档存储数据库之MongoDB基础入门
华为云重大变革:Cloud&AI 升至华为第四大 BG ,火力全开
[Python 1-6] Python tutorial 1 -- number
Python基础语法