当前位置:网站首页>喝汽水,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
边栏推荐
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Installing MacOS 11 Big Sur in virtual machine
- Xamarin 从零开始部署 iOS 上的 Walterlv.CloudKeyboard 应用
- 阿里撕下电商标签
- The most complete! Alibaba economy cloud original practice! (Internet disk link attached)
- 后端程序员必备:分布式事务基础篇
- 虚拟机中安装 macOS 11 big sur
- C语言I博客作业03
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- Shell uses. Net objects to send mail
猜你喜欢
如何将 PyTorch Lightning 模型部署到生产中
笔试面试题目:盛水最多的容器
What can your cloud server do? What is the purpose of cloud server?
Enabling education innovation and reconstruction with science and technology Huawei implements education informatization
Xamarin deploys IOS from scratch Walterlv.CloudKeyboard application
211考研失败后,熬夜了两个月拿下字节offer!【面经分享】
C语言I博客作业03
python基础教程python opencv pytesseract 验证码识别的实现
nat转换的ip跟端口ip不相同的解决方法
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]
随机推荐
The most complete! Alibaba economy cloud original practice! (Internet disk link attached)
你的云服务器可以用来做什么?云服务器有什么用途?
Windows下快递投递柜、寄存柜的软件初探
Flink的sink实战之一:初探
This paper analyzes the top ten Internet of things applications in 2020!
AQS analysis
How to write a resume and project
笔试面试题目:判断单链表是否有环
Implementation of verification code recognition in Python opencv pytesseract
It's 20% faster than python. Are you excited?
Istio流量管理--Ingress Gateway
From a friend recently Ali, Tencent, meituan and other P7 Python development post interview questions
虚拟机中安装 macOS 11 big sur
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Adobe Lightroom / LR 2021 software installation package (with installation tutorial)
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Hematemesis! Alibaba Android Development Manual! (Internet disk link attached)
吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)
Tight supply! Apple's iPhone 12 power chip capacity exposed
Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)