当前位置:网站首页>喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
2020-11-08 12:56:00 【osc_51airx3z】
第一种方法
#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("你有多少钱:");
scanf_s("%d", &money);
int ret = Qishui(money);
printf("可以买%d瓶汽水\n", ret);
system("pause");
return 0;
}
第二种方法
#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("你有多少钱:");
scanf_s("%d", &money);
int ret = Qishui(money);
printf("可以买%d瓶汽水\n", ret);
system("pause");
return 0;
}
版权声明
本文为[osc_51airx3z]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4263556/blog/4708158
边栏推荐
- How to write a resume and project
- 后端程序员必备:分布式事务基础篇
- python基础教程python opencv pytesseract 验证码识别的实现
- 渤海银行百万级罚单不断:李伏安却称治理完善,增速呈下滑趋势
- PMP考试通过心得分享
- Introduction to mongodb foundation of distributed document storage database
- On monotonous stack
- Automatically generate RSS feeds for docsify
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Improvement of rate limit for laravel8 update
猜你喜欢

Flink's sink: a preliminary study

阿里撕下电商标签

蘑菇街电商交易平台服务架构及改造优化历程(含PPT)

211考研失败后,熬夜了两个月拿下字节offer!【面经分享】

It's worth seeing! EMR elastic low cost offline big data analysis best practice (with network disk link)

Ali teaches you how to use the Internet of things platform! (Internet disk link attached)

Tight supply! Apple's iPhone 12 power chip capacity exposed

原创 | 数据资产确权浅议

How TCP protocol ensures reliable transmission

TCP协议如何确保可靠传输
随机推荐
Written interview topic: looking for the lost pig
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
This time Kwai tiktok is faster than shaking.
The most complete! Alibaba economy cloud original practice! (Internet disk link attached)
python基本语法 变量
YGC问题排查,又让我涨姿势了!
What can your cloud server do? What is the purpose of cloud server?
优化if-else代码的八种方案
Or talk No.19 | Facebook Dr. Tian Yuandong: black box optimization of hidden action set based on Monte Carlo tree search
华为云重大变革:Cloud&AI 升至华为第四大 BG ,火力全开
Flink从入门到真香(10、Sink数据输出-Elasticsearch)
Python基础语法
浅谈单调栈
蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
分布式文档存储数据库之MongoDB基础入门
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
python小工具:编码转换
The young generation of winner's programming life, the starting point of changing the world is hidden around
Automatically generate RSS feeds for docsify
TCP协议如何确保可靠传输