当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- AQS解析
- Rust: performance test criteria Library
- Python basic syntax
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Ali! Visual computing developer's series of manuals (with internet disk link)
- Analysis of istio access control
- 为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
- Istio流量管理--Ingress Gateway
- 阿里教你深入浅出玩转物联网平台!(附网盘链接)
- 阿里出品!视觉计算开发者系列手册(附网盘链接)
猜你喜欢

Rust: performance test criteria Library

Flink从入门到真香(10、Sink数据输出-Elasticsearch)

2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...

Python基础语法

一文读懂机器学习“数据中毒”

阿里出品!视觉计算开发者系列手册(附网盘链接)

PMP心得分享

供货紧张!苹果被曝 iPhone 12 电源芯片产能不足

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基本语法 变量
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]
一个方案提升Flutter内存利用率
Eight ways to optimize if else code
Ali! Visual computing developer's series of manuals (with internet disk link)
This time Kwai tiktok is faster than shaking.
分布式文档存储数据库之MongoDB基础入门
优化if-else代码的八种方案
C language I blog assignment 03
On monotonous stack
Win10 terminal + WSL 2 installation and configuration guide, exquisite development experience
擅长To C的腾讯,如何借腾讯云在这几个行业云市场占有率第一?
Flink from introduction to Zhenxiang (7. Sink data output file)
2 days, using 4 hours after work to develop a test tool
你的云服务器可以用来做什么?云服务器有什么用途?
Tidb performance competition 11.02-11.06
How to write a resume and project
最全!阿里巴巴经济体云原生实践!(附网盘链接)
Shell uses. Net objects to send mail
原创 | 数据资产确权浅议