当前位置:网站首页>喝汽水,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
边栏推荐
- Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
- VC + + specified directory file output by time
- Rust : 性能测试criterion库
- 为 Docsify 自动生成 RSS 订阅
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Share the experience of passing the PMP examination
- 如何将 PyTorch Lightning 模型部署到生产中
- 当Kubernetes遇到机密计算,看阿里巴巴如何保护容器内数据的安全!(附网盘链接)
- C language I blog assignment 03
- 211考研失败后,熬夜了两个月拿下字节offer!【面经分享】
猜你喜欢
解析Istio访问控制
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
AQS analysis
Harbor项目高手问答及赠书活动
Enabling education innovation and reconstruction with science and technology Huawei implements education informatization
TiDB 性能竞赛 11.02-11.06
Adobe media encoder / me 2021 software installation package (with installation tutorial)
Ali! Visual computing developer's series of manuals (with internet disk link)
Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
It's 20% faster than python. Are you excited?
随机推荐
笔试面试题目:判断单链表是否有环
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
一个方案提升Flutter内存利用率
211考研失败后,熬夜了两个月拿下字节offer!【面经分享】
TCP协议如何确保可靠传输
【Python 1-6】Python教程之——数字
Automatically generate RSS feeds for docsify
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Win10 terminal + WSL 2 installation and configuration guide, exquisite development experience
Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
值得一看!EMR弹性低成本离线大数据分析最佳实践(附网盘链接)
Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
分布式文档存储数据库之MongoDB基础入门
Ali! Visual computing developer's series of manuals (with internet disk link)
Xamarin 从零开始部署 iOS 上的 Walterlv.CloudKeyboard 应用
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)
Second assignment
How TCP protocol ensures reliable transmission
Adobe Lightroom /Lr 2021软件安装包(附安装教程)