当前位置:网站首页>喝汽水,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
边栏推荐
- 新的目标市场在哪里?锚定的产品是什么?| 十问2021中国企业服务
- 为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
- How to deploy pytorch lightning model to production
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- 适合c/c++新手学习的一些项目,别给我错过了!
- 优化if-else代码的八种方案
- Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
- Entry level! Teach you how to develop small programs without asking for help (with internet disk link)
- Bohai bank million level fines continue: Li Volta said that the governance is perfect, the growth rate is declining
- PMP心得分享
猜你喜欢
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
This time Kwai tiktok is faster than shaking.
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Rust : 性能测试criterion库
Hematemesis! Alibaba Android Development Manual! (Internet disk link attached)
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、电信、联通 ...
阿里教你深入浅出玩转物联网平台!(附网盘链接)
Entry level! Teach you how to develop small programs without asking for help (with internet disk link)
随机推荐
Powershell 使用.Net对象发送邮件
Flink: from introduction to Zhenxiang (3. Reading data from collection and file)
Adobe media encoder / me 2021 software installation package (with installation tutorial)
This paper analyzes the top ten Internet of things applications in 2020!
C语言I博客作业03
Flink's sink: a preliminary study
Ali! Visual computing developer's series of manuals (with internet disk link)
Ali tear off the e-commerce label
Implementation of verification code recognition in Python opencv pytesseract
Xamarin deploys IOS from scratch Walterlv.CloudKeyboard application
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
啥是数据库范式
Ubuntu20.04 access FTP server garbled problem + upload files
BCCOIN告诉您:年底最靠谱的投资项目是什么!
Or talk No.19 | Facebook Dr. Tian Yuandong: black box optimization of hidden action set based on Monte Carlo tree search
Share the experience of passing the PMP examination
This time Kwai tiktok is faster than shaking.
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
Mozi college SQL injection solution