当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Written interview topic: looking for the lost pig
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Stm32uberide download and install - GPIO basic configuration operation - debug (based on CMSIS DAP debug)
- 笔试面试题目:求缺失的最小正整数
- Adobe Lightroom / LR 2021 software installation package (with installation tutorial)
- 后端程序员必备:分布式事务基础篇
- 蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
- 不多不少,大学里必做的五件事(从我的大一说起)
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- What can your cloud server do? What is the purpose of cloud server?
猜你喜欢
OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
Q & A and book giving activities of harbor project experts
优化if-else代码的八种方案
When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)
Suitable for C / C + + novice learning some projects, do not give me to miss!
TiDB 性能竞赛 11.02-11.06
C language I blog assignment 03
Ali teaches you how to use the Internet of things platform! (Internet disk link attached)
Implementation of verification code recognition in Python opencv pytesseract
应届生年薪35w+ !倒挂老员工,互联网大厂薪资为何越来越高?
随机推荐
The most complete! Alibaba economy cloud original practice! (Internet disk link attached)
【Python 1-6】Python教程之——数字
PMP心得分享
Adobe media encoder / me 2021 software installation package (with installation tutorial)
最全!阿里巴巴经济体云原生实践!(附网盘链接)
应届生年薪35w+ !倒挂老员工,互联网大厂薪资为何越来越高?
Enabling education innovation and reconstruction with science and technology Huawei implements education informatization
STM32CubeIDE下载安装-GPIO基本配置操作-Debug调试(基于CMSIS DAP Debug)
Q & A and book giving activities of harbor project experts
Istio traffic management -- progress gateway
Bohai bank million level fines continue: Li Volta said that the governance is perfect, the growth rate is declining
Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
用科技赋能教育创新与重构 华为将教育信息化落到实处
Don't look! Full interpretation of Alibaba cloud's original data lake system! (Internet disk link attached)
吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)
用 Python 写出来的进度条,竟如此美妙~
Flink from introduction to Zhenxiang (10. Sink data output elasticsearch)
阿里撕下电商标签
Analysis of istio access control
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom