当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
- [Python 1-6] Python tutorial 1 -- number
- Adobe media encoder /Me 2021软件安装包(附安装教程)
- What is the database paradigm
- 在51CTO学院Get到PMP证书
- Win10 terminal + WSL 2 installation and configuration guide, exquisite development experience
- This time Kwai tiktok is faster than shaking.
- Tencent, which is good at to C, how to take advantage of Tencent's cloud market share in these industries?
- AQS解析
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
猜你喜欢

Get PMP certificate at 51CTO College

为 Docsify 自动生成 RSS 订阅

应届生年薪35w+ !倒挂老员工,互联网大厂薪资为何越来越高?

在51CTO学院Get到PMP证书
![211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]](/img/3b/00bc81122d330c9d59909994e61027.jpg)
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]

Flink从入门到真香(6、Flink实现UDF函数-实现更细粒度的控制流)

AQS解析

Personal current technology stack

What can your cloud server do? What is the purpose of cloud server?

Bohai bank million level fines continue: Li Volta said that the governance is perfect, the growth rate is declining
随机推荐
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
Flink从入门到真香(10、Sink数据输出-Elasticsearch)
第二次作业
Flink从入门到真香(6、Flink实现UDF函数-实现更细粒度的控制流)
Ubuntu20.04下访问FTP服务器乱码问题+上传文件
Flink from introduction to Zhenxiang (10. Sink data output elasticsearch)
PMP心得分享
AQS analysis
吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)
Q & A and book giving activities of harbor project experts
原创 | 数据资产确权浅议
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
华为云重大变革:Cloud&AI 升至华为第四大 BG ,火力全开
来自朋友最近阿里、腾讯、美团等P7级Python开发岗位面试题
Win10 Terminal + WSL 2 安装配置指南,精致开发体验
nat转换的ip跟端口ip不相同的解决方法
最全!阿里巴巴经济体云原生实践!(附网盘链接)
Powershell 使用.Net对象发送邮件
Adobe media encoder /Me 2021软件安装包(附安装教程)